|
Xarzu wrote: How would that look like in Visual C#?
It would look better.
You use an enum, which gives it more structure. This will also give you the possible values to use right in the intellisense, so you don't have to wade through loads of header files to find out which constants you can use.
[Flags]
public enum Feeling {
Happy = 1,
Hungry = 2,
Free = 4,
Cold = 8
}
The Flags attribute enables you to perform bitwise operations on the enum values:
Feeling xarzu = Feeling.Happy | Feeling.Hungry;
if ((xarzu & Feeling.Happy) != 0) MessageBox.Show("Xarzu is happy.");
The data type that the enum uses by default is int , as that's the most efficient type. You can specify a different type like an uint if you like, but there is rarely any reason for that.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
viterbi algorithm in c#
can any one explain wats happening in the code
i need working of this code,,, antyone pls
using System;
using System.Collections.Generic;
using System.Text;
namespace Viterbi
{
public class ForwardViterbi
{
// The Class Globals
string[] states;
string[] observations;
double[] startProbability;
double[,] transitionProbability;
double[,] emissionProbability;
double scaleFactor;
//Computed Variables
int[] vPath; //The Viterbi Path
double[] vProbs;
//----------------------------------------------------------------------
// The Getters or Accessors
public int[] VPath
{
get { return vPath; }
}
public double[] VProbs
{
get { return vProbs; }
}
//----------------------------------------------------------------------
//Constructor
public ForwardViterbi(string[] states, string[] observations, double[] startProbability, double[,] transitionProbability, double[,] emissionProbability, double scaleFactor)
{
this.states = states;
this.observations = observations;
this.startProbability = startProbability;
this.transitionProbability = transitionProbability;
this.emissionProbability = emissionProbability;
this.scaleFactor = scaleFactor;
}
//----------------------------------------------------------------------
//The Methods
public void Process(int[] problem)
{
double[,] T = new double[states.Length, 3]; //We will store the probability sequence for the Viterbi Path
vPath = new int[problem.Length];
vProbs = new double[problem.Length];
//initialize T
//------------------------------------------------------------------
for (int state = 0; state < states.Length; state++)
{
T[state, 0] = startProbability[state];
T[state, 1] = state;
T[state, 2] = startProbability[state];
}
for (int output = 0; output < problem.Length; output++)
{
double[,] U = new double[states.Length, 3]; //We will use this array to calculate the future probabilities
Console.WriteLine("\nTesting hypothesis {0} ({1})", output, observations[problem[output]]);
double highest = 0;
for (int nextState = 0; nextState < states.Length; nextState++)
{
double total = 0;
double argMax = 0;
double valMax = 0;
Console.WriteLine(" Estimating probability for future state {0} ({1})", nextState, states[nextState]);
for (int state = 0; state < states.Length; state++)
{
Console.WriteLine(" The testing state is {0} ({1})", states[state], state);
double prob = T[state, 0];
double v_path = T[state, 1];
double v_prob = T[state, 2];
double p = emissionProbability[state, problem[output]] * transitionProbability[state, nextState] * scaleFactor;
prob *= p;
v_prob *= p;
total += prob;
if (v_prob > valMax)
{
valMax = v_prob;
argMax = nextState;
}
Console.WriteLine(" VProbability of {0} is {1} with scale {2}^{3}", states[nextState], v_prob, scaleFactor, output + 1);
if (v_prob > highest)
{
highest = v_prob;
vPath[output] = nextState;
vProbs[output] = v_prob;
}
}
U[nextState, 0] = total;
U[nextState, 1] = argMax;
U[nextState, 2] = valMax;
}
T = U;
Console.WriteLine("The highest probability was {0} in state {1} (scale factor of {2}^{3})", highest, states[vPath[output]], scaleFactor, output + 1);
}
//Apply SumMax
double Total = 0;
double ValMax = 0;
for (int state = 0; state < states.Length; state++)
{
double prob = T[state, 0];
double v_path = T[state, 1];
double v_prob = T[state, 2];
Total += prob;
if (v_prob > ValMax)
{
ValMax = v_prob;
}
}
Console.WriteLine("\nAnalysis: Total probability (sum of all paths) for the given state is :: {0}\nThe Viterbi Path Probability is :: {1}", Total, ValMax);
Console.WriteLine("The above results are presented with a scale factor of {0}^{1}", scaleFactor, problem.Length);
}
}; // end Forward Viterbi Class
}
|
|
|
|
|
No-one is going to read all of this, or do your homework for you. How about you tell us which line is not doing what you expect ? Have you spent some time in the debugger to see where the code is not following the logic you hoped for ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
dear friend
i spent time and studied.. but these lines i don understand the logic... can u help me pls
if (v_prob > valMax)
{
valMax = v_prob;
argMax = nextState;
}
Console.WriteLine(" VProbability of {0} is {1} with scale {2}^{3}", states[nextState], v_prob, scaleFactor, output + 1);
if (v_prob > highest)
{
highest = v_prob;
vPath[output] = nextState;
vProbs[output] = v_prob;
}
}
U[nextState, 0] = total;
U[nextState, 1] = argMax;
U[nextState, 2] = valMax;
}
T = U;
Console.WriteLine("The highest probability was {0} in state {1} (scale factor of {2}^{3})", highest, states[vPath[output]], scaleFactor, output + 1);
}
//Apply SumMax
double Total = 0;
double ValMax = 0;
for (int state = 0; state < states.Length; state++)
{
double prob = T[state, 0];
double v_path = T[state, 1];
double v_prob = T[state, 2];
the quieter u become more u hear
|
|
|
|
|
How about no scott? Scotty says no? howbowudoee? Ladies and gentlemen scotty don't.
|
|
|
|
|
Hi,
The Viterbi algorithm is an interesting one, IMO its working is best explained and understood using
several graphics, rather than code. Anyway it is beyond the scope of a forum like this one, you would
better look it up in a specialized book, such as a digital communications course.
Once you fully understand the allgorithm, I suggest you take a really really simple test case,
and work it out by hand, then run it through the program you want debugged, and compare the results
step by step. Don't expect too much help from this forum, unless you prove you understand and really
tried, but got stuck at a very specific point.
|
|
|
|
|
Luc Pattyn wrote: Once you fully understand the allgorithm..
..write an article about it and post it here!
Luc Pattyn wrote: Don't expect too much help from this forum
Sad, but true. "Gimme codez, urgent" makes one cynical.
The noise is going up in this forum, and it's killing the music..
I are troll
|
|
|
|
|
Eddy Vluggen wrote: "Gimme codez, urgent" makes one cynical.
The noise is going up in this forum,
That was not the point, the topic is rather complex an not very suited for a text-only forum
that focuses on small programming issues.
|
|
|
|
|
Fortunately, one can use pictures when submitting an article
I are troll
|
|
|
|
|
I am writing a windows service in c# and am loading a crystal report. I need to export this report as a jpg file to disk or to take some kind of image stream which I can load into a bitmap or image object. I can export to a PDF but this is no use to me.
Any ideas?
|
|
|
|
|
Have never had the need to use Crystal Reports myself but this link[^] looks like it might have the answer.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi thanks for the reply. but.. the link takes me to a page describing how to "export crystal as image" perhaps you gave me wrong link? or else my english writing is a total failure. i need help on how to list parameter values dynamically created by the report.
Br
Tomas
If it' stuck, DO NOT pull harder!
|
|
|
|
|
c0ax_lx wrote: help on how to list parameter values dynamically
That's not the question you asked!:
c0ax_lx wrote: I need to export this report as a jpg file to disk or to take some kind of image stream which I can load into a bitmap or image object.
I'd start a new thread seeing as it's a totally new question.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
D'uh! i'm really sorry! this wasnt even my post! not used to see crystal report questions here *sigh*. well. You are totally correct, your post is the answer to the question.
so i'll just shut up now and try to find my own post.
hmm. i feel stupid.
Rgds
Tomas
If it' stuck, DO NOT pull harder!
|
|
|
|
|
LOL, no worries - I didn't check the user name(s).
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Your post here[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
How can I play flash on C# form? Can you help me about that please?
Thanks in advance.
|
|
|
|
|
Link 1[^]
Link 2[^]
Both do exactly what you should have done before posting and you might have been finished this project (or the part that you asked about) by now instead of waiting for another to do a simple search you could have done yourself.
|
|
|
|
|
The problem is that you answered in just about 12 minutes. You're never going to teach him by giving him such good service.
Scott
|
|
|
|
|
Maybe he will say thats 12 minutes I could have saved by typing in googles URL
|
|
|
|
|
Maybe...but don't hold your breath.
|
|
|
|
|
|
|
What I want to do is something like this, which fails because NumericID is an int type.
ds_Search.SelectParameters.Add("NumericID", "%");
The only relevant hit I was able to find was from the dubious quality website expert exchange (first result, very bottom of the page)[^]which said I either needed to change the DB to have a string field (not possible) or write seperate queries for the wildcards (impractical because there're dozens that would need duplicated).
Are those really my only options?
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
A numeric is not a string, but you can convert the NumericId to a string in a query. Only then can it be compared with a string.
Jean-Christophe Grégoire
|
|
|
|
|