

Apologies for the shouting but this is important.
When answering a question please:
 Read the question carefully
 Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
 If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
 If the question is inappropriate then click the 'vote to remove message' button
Insults, slapdowns and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Cofounder
Microsoft C++ MVP





For those new to message boards please try to follow a few simple rules when posting your question. Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
 Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
 Keep the subject line brief, but descriptive. eg "File Serialization problem"
 Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
 Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
 Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
 If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
 Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
 Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
 Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
 If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
 No advertising or soliciting.
 We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Cofounder
Microsoft C++ MVP





Does it make any sense to test decision tree on dataset generated randomly? example: (the output "true"/"false" is not conditioned on parameters 110)
for (int i = 0; i < l; i++)
{
string[] new_ex = new string[11];
new_ex[0] = ThreadSafeRandom.ThisThreadsRandom.Next(60)%5 == 1 ? "true" : "false";
for (int r = 1; r < 5; r++)
new_ex[r] = (ThreadSafeRandom.ThisThreadsRandom.Next(60)%3).ToString();
for (int r = 5; r < 7; r++)
new_ex[r] = (ThreadSafeRandom.ThisThreadsRandom.Next(60)%3).ToString();
for (int r = 7; r < 9; r++)
new_ex[r] = (ThreadSafeRandom.ThisThreadsRandom.Next(20)%5).ToString();
for (int r = 9; r < 11; r++)
new_ex[r] = (ThreadSafeRandom.ThisThreadsRandom.Next(4)).ToString();
dataset.Add(new_ex);
}





If your goal was obfuscation, you've accomplished that.
(Consider a generic string LIST and .Add method in the main body).





coding issues are not relevant, its more like theoretical question but thanks for hints





I've used random number generation to simulate queues / arrival rates; so yes, decision trees based on random data has it's place.





Let's assume that ‘k’ is an integer that indicate and reveals exactly the length of subset that sum to 0. Thus length of subset to pick is determined by ‘k’. If I would like to pick only ‘k’ distinct set of integers from any given set of integers in polynomial time without having needed to check through every possible length other than the chosen length. What will be the time complexity and the size of subset for every given subset sum problem?
For example:
Given a set of integers {3, 17, 30, 12, 8 15, 7, 45, 16, 9} is there a nonempty subset whose sum is zero? Yes, because k = 5. Output {3, 17, 8, 15, 9 = 0}
Given a set of integers {12, 5, 6, 7, 22} is there a nonempty subset whose sum is zero? No, because k = null. Output none
Given a set of integers {8, 20, 3, 35, 2, 3, 40, 7, 16, 9, 25} is there a nonempty subset whose sum is zero? Yes, because k = 5. Output {8, 3, 2, 9 = 0}
Given a set of integers {2, 10, 15, 20, 3, 12, 45, 6, 17, 1, 18, 5} is there a nonempty subset whose sum is zero? Yes because k = 9. Output {2, 15, 3, 12, 45, 6, 17, 1, 5 = 0}
etc..
modified yesterday.






See my April 2014 Tip/Trick: Subset  Sum Problem with Numeric Collections [^]
which includes a very efficient way to generate all possible combinations of n items.
Optimizing to make it more efficient for combinations of n choose k should not be too difficult.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
 G.K. Chesterton





Hello,
I have a class Tree
public class Tree{
private int tree_height;
private int tree_width;
private int nodes_count;
private List<Node> tree_nodes;}
and class node
public class Node{
private object state;
private int ordering;
private int height;
private int parent;}
I would like to create a method to add a branch to a tree
here is my code:
public void AddBranch(Tree branch, int node_num)
{
if (nodes_count >= node_num && node_num > 0)
{
int last_el_ordering = nodes_count,
first_parent_height = tree_nodes[node_num  1].Height,
first_parent_ordering = tree_nodes[node_num  1].Ordering;
tree_nodes.Add(new Node(branch.Tree_nodes.First().State, last_el_ordering + 1, first_parent_ordering, first_parent_height + 1));
foreach (Node el in branch.Tree_nodes.Skip(1))
tree_nodes.Add(new Node(el.State, el.Ordering + last_el_ordering, el.Parent + last_el_ordering, el.Height + first_parent_height));
tree_nodes = tree_nodes.OrderBy(match => match.Height).ToList();
int i = 1;
foreach (Node el in tree_nodes)
{
List<Node> temp = tree_nodes.ToList().FindAll(match => match.Parent == el.Ordering).ToList();
el.Ordering = i++;
if (temp.Count() > 0)
foreach (Node el2 in temp)
el2.Parent = el.Ordering;
}
}
}
I have a little problem when I add new node after connecting two trees eg: to tree
first
a b c
false false false
i want to add a branch
d
false
to the first node
The label "false" which is child of "d" is getting misplaced and I cannot figure out why. Please help.
the input
Tree testing_tree1 = new Tree(new Node("start"));
List<string> temp = new List<string> { "a", "b", "c" };
foreach(string el in temp)
testing_tree1.AddBranch(new Tree(new Node(el)),1);
for (int i = 0; i < 3; i++)
testing_tree1.AddBranch(new Tree(new Node("false")), i+2);
Tree testing_tree2 = new Tree(new Node("d"));
testing_tree2.AddBranch(new Tree(new Node("false")), 1);
testing_tree1.AddBranch(testing_tree2, 1);
testing_tree1.DisplayTree();
Console.Read();
the output
tree depth: 3 tree width: 4 nodes count: 9
Node number:1, Node parent:1, Node height:1, Node value:start
Node number:2, Node parent:1, Node height:2, Node value:a
Node number:3, Node parent:1, Node height:2, Node value:b
Node number:4, Node parent:1, Node height:2, Node value:c
Node number:5, Node parent:1, Node height:2, Node value
Node number:6, Node parent:2, Node height:3, Node value:false
Node number:7, Node parent:3, Node height:3, Node value:false
Node number:8, Node parent:4, Node height:3, Node value:false
Node number:9, Node parent:8, Node height:3, Node value:false





Use the debugger and see what your code is really doing.
The debugger permit you to execute your code line by line and inspect variables during execution.
You should see that somewhere, your code is not doing as expected.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Good morning sirs, please I need your help on a project I am working on, I am new to this discussion forum on algorithm(but not to CodeProject) and new to algorithm itself, someone directed me here. I started a project on algorithm for plotting SkewTlnP chart, I have written all other algorithms to do all needed calculations including that of the grids but am stock on how to write the main algorithm for plotting the SkewT chart and the type of graphics library to use. am using c# language and vs2010 IDE. thanks





Don't try to write your own graphics routines.
There are a number of open source and commercial libraries available. For the commercial ones, use their trial version.
Create a wrapper for your library calls so you can try different options (VisiBlox; SciChart; etc.).
If your product becomes commercially viable, then get a license if necessary.





OK, to summarise your problem, you have more than 3 dimensions to plot on a graph.
When plotting 3 dimensions on a graph, we use a projection to map these to 2 dimensions. This is based on the orientation of the axes. You need to create a similar projection from you multidimensional coordinates to a 2 dimensional plane.
Check out 4D Visualization: Projections (1)[^] as a starting point.





Hello,
Warning: my tree class does not contain links between nodes. To connect two nodes I use leafs. Parent > Node(linking) > Node(desired). That way I get "Parameter1" > "0" > "false".
Description: examples is list of string[] such that string[0] is "false" or "true" and the rest is "0"  "10" strings as attributes values. AttributesVector has Names  List of attributes and Possible_values List with max value of attributes (10 for all). My output is showing all possible parameters values (0, 1, 2, 3,..., 10) with response 'true' or 'false' and it should consider only the values that make any sense (attribute 1 never get value 0). I don't know why. I also get too many nodes in the tree. I have datasets that I can provide along with csv reader.
private Tree DecisionTreeLearning(List<string[]> examples, AttributesVector attributes_vector, Tree default_tree)
{
if (examples.Count() == 0)
return default_tree;
if (AllExamplesSameClassification(examples))
return new Tree(new Node(examples.First()[0]));
if (attributes_vector.Vector_length == 0)
return MajorityValue(examples);
string chosen_attribute = ChooseAttribute(examples, attributes_vector);
Tree current_tree = new Tree(new Node(chosen_attribute));
Tree current_majority_value = MajorityValue(examples);
int chosen_attr_index = attributes_vector.Names.FindIndex(match => match == chosen_attribute);
int temp2 = 2;
for (int i = 0; i < attributes_vector.Possible_values[chosen_attr_index] + 1; i++)
{
List<string[]> matching_examples = examples.FindAll(match => match[chosen_attr_index] == i.ToString());
List<string> new_attributes_names = new List<string> { };
foreach (string el in attributes_vector.Names)
{
string temp = string.Copy(el);
new_attributes_names.Add(temp);
}
new_attributes_names.RemoveAt(chosen_attr_index);
List<int> new_list_of_possible_values = new List<int> { };
foreach (int el in attributes_vector.Possible_values)
{
int temp = el;
new_list_of_possible_values.Add(temp);
}
new_list_of_possible_values.RemoveAt(chosen_attr_index);
AttributesVector new_attributes_vector = new AttributesVector(new_attributes_names, new_list_of_possible_values);
Tree subtree = new Tree();
subtree = DecisionTreeLearning(matching_examples, new_attributes_vector, current_majority_value);
current_tree.AddBranch(new Tree(new Node(i.ToString())), 1);
current_tree.AddBranch(subtree, temp2++);
}
return current_tree;
}
modified 29Jan16 5:17am.






I have 7500 points with me. when I plot in excel it will draw a sine wave with a glitch. I want to know the exact start and end position of the glitch. Is there any algorithm which I can use to find this. i am developing the application in C#. Below are 7500





i don't know if this is optimal, but it's easy:
if you have a nice big smooth sine wave, you can simply go through each pair of points in order, calculating the slope between each pair. the glitch will start at the spot where the slope changes by more than some threshold. to find the end of the glitch, do the same in reverse.





Another (more expensive) way would be to take the Fourier transform of your data, which should give you a sharp peak representing the sine wave, and highfrequency stuff representing the glitch. Subtract the sharp peak from the transform, and then use an inverse transform back to the time domain.
You should get a dataset which is very close to zero for most of the range, differing from zero only at the glitch.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time  a tremendous whack.
Winston Churchill





Imagine a circular table with a number of metal weights hanging off the table on strings of the same length spaced at regular intervals around the circle. Let's say there are twelve weights.
Let's also assume some loss of "pull" here due to friction, some "inertia."
Now, imagine that all the weights are equal, and that you are looking down at the table from above it. You see all the strings connect to one central knot, and, the weights being equal, that knot appears in the center of the circular table.
I can't explain to you why I've got this bug in my brain to model how the location of the knot would move in response to variation in the weights, it's just something that came to my mind and interested me.
Is there a type of algorithm that would be useful for dealing with weighted vectors and relative forces ?
thanks, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
modified 24Jan16 5:36am.





I'm not sure I see what you mean here. But if all strings are attached to a freely hanging weight surely the resulting force would be a vector depending on F=m*a? if the weight is heavier on one side surely the weights would be pulled towards the heavier object?





Kenneth Haugland wrote: if the weight is heavier on one side surely the weights would be pulled towards the heavier object? Yes.
But, what (in my mind is the 'nonobvious') I am interested in is a situation like this:
1. there are 12 weights that differ, but their relative 'pulls' balance so that the 'knot' is a the center of the 'table.'
2. now imagine the weight at '11 o'clock' becomes #x grams heavier; what is the displacement of the 'knot' from the center.
3. now imagine that each weight has some nonlinear function governing the relationship between its 'pull' and its weightvalue: so, a change of #x grams in the weight at 11 o'clock changes based on the function's return value.
A realworld example that comes to mind is in Bezier splines, where the control points have an interesting functional relationship to the rendered curve.
thanks, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin





If you want friction involved you would have to use numerical methods unless you are going to restrict the movements of the threads severely. And without friction, I think the problem will be trivial, at least if you have the position of the weights fixed.





The general approach to such mechanical problems is to set up a set of coupled differential equations, which together describe the motion of each weight (and therefore  of the knot). Many packages for numerical solution of differential equations exist.
However, this isn't as simple a problem as it appears at first. If you take a simple case where exactly one weight is heavier than the others, the knot will start sliding towards the heavy weight. This means that the knot is no longer centred in the circle, and the strings are chords, not radii. This means that the forces acting on the edge of the table (caused by the strings) now have transverse components, as well.
At some point, the transverse force for each string will be enough to overcome the static friction between the edge of the table and the string. At this point, the weight will start sliding around the edge of the table (toward the heavy weight?). This will in turn change the dynamics of the problem even more.
This sliding effect may happen even with equal weights, if the initial position of the knot is sufficiently offcentre.
The analytical solution of this problem would probably be worth a nice paper in a peerreviewed Physics journal.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time  a tremendous whack.
Winston Churchill





Modeling wise I would expect that understanding the problem would be easier starting with a simpler model.
Start with a square table.
There is no friction on the table or edges.
There are 3 weights: A, B, C
A and B each weigh half as much as C.
A and B are hanging off the left side of the table. There is a 30 degree angle between the ropes and the knot. C is hanging off the right side.
The ropes are very long and have no weight.
Now double the weight of C.
My expectation would be that the knot would move to the right and the angle would decrease.
Fixing the ropes through rings at the table edge would make the force calculations easier (x and y) because the ropes should move (due to force in one direction.) Then one would need to apply calculus to solve once the rings are moved.
Then add three weights on one side and repeat.
I would expect that one would then 'round' the square table to progressively arrive at the final solution.




