Can someone please confirm or correct my understanding of the order of values when using Value.CreateBatch instead of MinibatchSource?
Assuming the CTF equivalent is:
|x 1 2 3
|x 4 5 6
|x 7 8 9
Would a batch of size 3 become (a) 1 2 3 4 5 6 7 8 9 or (b) 1 4 7 2 5 8 3 6 9?
My current perception is (a) however I'd greatly appreciate this being confirmed or corrected. Many thanks in advance.
Of course, a) is the correct answer. In each line x is the name of the input data followed by the input data itself.
It is implicated in this tutorial for CNTK: https://cntk.ai/pythondocs/CNTK_103C_MNIST_MultiLayerPerceptron.html#Data-reading
and I also can tell it from my experience.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I've thought of using a if statement to say if that number has already been produced into my line change the number which it was going to produce into a different number other then that, but I must of wrote it incorrect since it does not work.
Let's consider a sequence of random hex "digits" :
f 5 3 0 0 5 e 8 e 8 5 6 f
A naïve approach would try to check if the previous number is equal to the next in the sequence and discard it.
That will not work since only a small subset of the duplicated numbers will be come in direct sequence.
What you will need is to keep a track of the ALL numbers already present.
if you store your final sequence in an array you could check for each element, as long as the number of the desired elements is low.
For example :
f (first elements nothing to check agains, add it)
f 5 (check against index 0-0 , f, not present add it)
f 5 3 (check
against index 0-1 , 3, not present add it)
f 5 3 0 (check against
index 0-2 , 0, not present add it)
f 5 3 0 0 (check against index
0-3 , 0 , found - skip it)
f 5 3 0 5 (check against index 0-3 , 5 ,
found - skip it)
f 5 3 0
8 (check against index 0-3 , 8, not
present add it)
f 5 3 0 8 e (check against index 0-4 , e, not
present add it)
f 5 3 0 8 e
and so on. This is basically what a human eye would do, if you cannot keep all the numbers in your head.
If the sequence is large scanning the output array will quickly become too inefficient and slow.
There ways to optimize the check by using hash sets/maps.(see Remove duplicate values from JS array and Selecting Unique Elements From a List in C# )
If the number of possible elements is low, you might want a "shuffle" to get your output (see Random shuffling of an array).
One of the .Net Core versions (I'm not sure which) introduced an optimisation such that if you write code like this:
int smallest = new[]{ 7, 2, 4, 6, 0, 1, 6, 9, 8 }.OrderBy(i => i).First();
then its complexity is O(N) rather than O(N.Log(N)).
Is this documented anywhere? I don't want to rely on this optimisation if it isn't "official".
Sample code that shows the difference between .Net Core and .Net Framework:
using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo
{
static class Program
{
static void Main()
{
int[] test = { 7, 2, 4, 6, 0, 1, 6, 9, 8 };
var comparer = new Comparer();
var _ = test.OrderBy(i => i, comparer).First();
}
}
class Comparer : IComparer<int>
{
public int Compare(int x, int y)
{
Console.WriteLine($"Comparing {x} with {y}");
return x.CompareTo(y);
}
}
}
Try it online with .Net Framework: https://dotnetfiddle.net/XItXYL
Try it online with .Net Core: https://dotnetfiddle.net/swlc0O
Output with .Net Framework 4.8:
Comparing 0 with 7
Comparing 0 with 8
Comparing 0 with 9
Comparing 0 with 6
Comparing 0 with 1
Comparing 0 with 0
Comparing 0 with 2
Comparing 0 with 6
Comparing 0 with 4
Comparing 0 with 2
Comparing 0 with 0
Comparing 7 with 2
Comparing 7 with 4
Comparing 7 with 6
Comparing 7 with 7
Comparing 7 with 8
Comparing 7 with 9
Comparing 7 with 6
Comparing 7 with 1
Comparing 7 with 7
Comparing 7 with 1
Comparing 9 with 7
Comparing 9 with 9
Comparing 9 with 8
Comparing 7 with 7
Comparing 7 with 8
Comparing 7 with 7
Comparing 6 with 2
Comparing 6 with 4
Comparing 6 with 6
Comparing 6 with 1
Comparing 6 with 6
Comparing 6 with 6
Comparing 6 with 1
Comparing 6 with 6
Comparing 6 with 6
Comparing 4 with 2
Comparing 4 with 4
Comparing 4 with 1
Comparing 2 with 2
Comparing 2 with 1
Output for .Net Core 3.1:
Comparing 2 with 7
Comparing 4 with 2
Comparing 6 with 2
Comparing 0 with 2
Comparing 1 with 0
Comparing 6 with 0
Comparing 9 with 0
Comparing 8 with 0
The answer to the question "Is this optimisation documented" is: Yes (kind-of).
See https://github.com/dotnet/runtime/issues/14867 for the discussion and links to the GitHub commits that implement it.
This isn't officially documented in the Microsoft documentation on those LINQ operators (OrderBy and First).
This is intentional. Once a behavior is officially documented this way, any change to that behavior becomes a breaking change, which may limit the developers' ability to make other optimizations which may be even more beneficial. If you are going to rely on specific implementation details, you should probably write your own method for this purpose.
That said, it's relatively rare for the O(n) versus O(n log(n)) complexity to make the difference between acceptable and unacceptable performance in an application. Consider carefully whether you're engaging in premature optimization.
I need help with sorting. I have table of numbers stored as Int32[,] array
1 2 3 4 5
5 6 7 8 6
9 10 11 12 7
13 14 15 16 8
and I need to sort it (lines not columns) according to another array for example 1 8 3 2.
Length of second array and number of lines in first always match. I know you can use Array.Sort(firstArray, secondArray); to sort first array and change second so indexes matches but that works only if second array is 1D.
Can anyone help? I know you can create comparator but how to create it for this case?
Thanks for responses in advance...
PS: I tried to find solutions here, nothing really helped and I have been trying for a while now...
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How would I figure out the next number to come in a pattern programatically in C#?
For example, if i had a pattern (3, 6, 9, 12), how would I programatically figure out that the next number is 15, and then 21, and so on?
Thanks.
Well, first you need to know the type of pattern or programatically figure that out. Linear number patterns increase by addition or subtraction. Exponential patterns increase by multiplication or division. With that, you have to start at the first number and determine the difference. Then look at the next number and see if it increases by the same amount. If it does, you have the pattern and just add the difference to the last number. If its not, its an exponential function and then you need to determine how much it increases with each number in the pattern, to project the next one.
Without seeing code, I can only show you the concept. Hope it helps!
You may find this useful.
Dangit, my response got lost with wireless failure. Lemme try again:
You could do it as a breadth-first search on combinations from a RPN language. Start with your pattern on the stack; ignore stack underflows, as they indicate that you're at the sequence seed. Use basic operators and single digits, for a good balance between expressive power and not exploding the search space too much. For example (and obviously, showing only some interesting points in the search space):
for +:
3 +: Stack Underflow - ignore
3 6 +: 9
3 6 9 +: 15 - wrong
for *:
3 *: SU
3 6 *: 18 - wrong
for 1:
3 1: 1 - wrong
for + -:
3 + -: SU
3 6 + -: SU
3 6 9 + -: -12 - wrong
for 3 +:
3 3 +: 6
3 6 3 +: 9
3 6 9 3 +: 12
success
next:
3 6 9 12 3 +: 15
3 6 9 12 15 3 +: 18
This will produce the simplest explanation for the sequence. As Samuel Edwin Ward notes, for all we know, there could be a complex algorithm that produces 4 as the next item, or "banana", for that matter. For instance, many people here would instantly "know" the next term in this sequence:
1
2
"fizz"
4
?
(The answer is, "obviously", "buzz", even though the pattern is not actually demonstrated in the example, only our experience.)
EDIT: Stack Underflow, not Overflow :/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Combination Generator in Linq
I am looking of an algorithm (using C#) that can
find all the combinations of specified numbers.
Example:
Numbers:
1 2 3
Combinations:
1
2
3
12
13
21
23
31
32
123
132
213
231
312
321
Only rule: No repetitions of numbers
I have looked around Google, Stackoverflow, as well as numerous other sites.
I would list some of my code, but I have had no success getting anything to work along the right lines.
EDIT:
The intention of this is using the generated numbers as the positions of characters in a word. I am creating a word finder, so basically this is what it is being used for:
Program generates:
0
1
01
10
From numbers: 0 1
The program got the numbers 0 and 1 from the user inputting for instance "no".
Example code:
string input = Console.ReadLine();
int size = input.Length; //This is where the 0 and 1 come from
Therefore the different combinations would rearrange the letters, using the length of the inputted word as the base, then comparing it to a word list, I could find existing words.
What you really need is a proper utilization of recursion. I think Permutations in C# Using Recursion is exactly what you are looking for.
I'll do more research as I have time and try to improve my answer.
Your program is dealing with combinatorial math (which you can google and read about). There is a formula for calculating your answer. Your question falls under the "Pick x from n" variety with respect to order.