public DistributionSpaceIterator_SingleGaussian(IBlauSpace space, IBlauSpaceIterator meanIter, IBlauSpaceIterator stdIter) { _ds = new DistributionSpace_SingleGaussian(space, meanIter.clone(), stdIter.clone()); _std = _ds.StdIterator.next(); _mean = _ds.MeanIterator.next(); _current = new Distribution_Gaussian(space, _mean, _std); }
public Agent0xA(IBlauPoint coordinates, IAgentFactory creator, int id) : base(coordinates, creator, id, 0.0) { _G = coordinates.getCoordinate(coordinates.Space.getAxisIndex(GainCutoff_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my aggressiveness to: "+_aggressiveness); SetMetricValue(GainCutoff_PROPERTYNAME, _G); _L = coordinates.getCoordinate(coordinates.Space.getAxisIndex(LossCutoff_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); SetMetricValue(LossCutoff_PROPERTYNAME, _L); _Tdouble = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Type_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); if (_Tdouble < 0.0) { _T = -1; } else { _T = +1; } SetMetricValue(Type_PROPERTYNAME, _T); _myTrades = 0; SetMetricValue(TotalTrades_METRICNAME, (double)_myTrades); _myOrders = 0; SetMetricValue(TotalOrders_METRICNAME, (double)_myOrders); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have iniitialized TotalTrades metric to: "+GetMetricValue(TotalTrades_METRICNAME)); }
// retrieve next BlauSpace point public IBlauPoint next() { IBlauPoint p = getCurrentBlauPoint(); if (this.BlauSpace.Dimension > 0) { int dim = this.BlauSpace.Dimension - 1; bool finishedIncrement = false; while (!finishedIncrement) { this.setCoordinate(dim, this.getCoordinate(dim) + 1); if (this.getCoordinate(dim) == this.getSteps(dim) + 1) { this.setCoordinate(dim, 0); dim--; if (dim < 0) { _done = true; finishedIncrement = true; } } else { finishedIncrement = true; } } } else { _done = true; } return(p); }
protected override IAgent create(IBlauPoint pt, IAgentFactory creator, int id) { SingletonLogger.Instance().InfoLog(typeof(Agent0x1), "Agent0x1_Factory creating agent " + id); IAgent dupe = new Agent0x1(pt, creator, id); return(dupe); }
protected override IAgent create(IBlauPoint pt, IAgentFactory creator, int id) { SingletonLogger.Instance().InfoLog(typeof(Agent1x0), "Agent1x0_Factory creating agent " + id); IAgent dupe = new Agent1x0(pt, creator, id, _lambda, _gamma, _burnin); return(dupe); }
public override IBlauPoint getSample() { IBlauPoint answer = _current; BlauPoint p = new BlauPoint(this.SampleSpace); for (int i = 0; i < this.SampleSpace.Dimension; i++) { p.setCoordinate(i, _current.getCoordinate(i)); } for (int i = 0; i < this.SampleSpace.Dimension; i++) { if (p.getCoordinate(i) + _step > this.SampleSpace.getAxis(i).MaximumValue) { p.setCoordinate(i, this.SampleSpace.getAxis(i).MinimumValue); if (i == this.SampleSpace.Dimension) { p = new BlauPoint(this.SampleSpace); break; } } else { p.setCoordinate(i, _step + p.getCoordinate(i)); break; } } _current = p; return(answer); }
public double eval(IBlauPoint bp) { IBlauPoint qp = Lattice.quantize(bp); if (_evaluationData.ContainsKey(qp)) { return(_evaluationData[qp]); } throw new Exception("No evaluation found for specified IBlauPoint in BlauSpaceEvaluation!"); }
// copy constructor public BlauPoint(IBlauPoint orig) { _space = orig.Space; _coords = new double [orig.Space.Dimension]; for (int i = 0; i < orig.Space.Dimension; i++) { _coords[i] = orig.getCoordinate(i); } _dirty = true; }
private void FillTemplateDistributionParameters(IBlauPoint parms) { for (int i = 0; i < parms.Space.Dimension; i++) { //SingletonLogger.Instance().DebugLog(typeof(DistributionSpaceIterator), "now filling param "+i+" with "+parms.getCoordinate(i)); _templateDistribution.setParam(i, parms.getCoordinate(i)); //Console.WriteLine("Now filling param "+i+" with "+parms.getCoordinate(i)); } //Console.WriteLine("the template dist is now: "+_templateDistribution); }
public Agent0xB(IBlauPoint coordinates, IAgentFactory creator, int id) : base(coordinates, creator, id, 0.0) { _G = coordinates.getCoordinate(coordinates.Space.getAxisIndex(GainCutoff_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my aggressiveness to: "+_aggressiveness); SetMetricValue(GainCutoff_PROPERTYNAME, _G); if (_G < 0.0) { throw new Exception("Gain cutoff must be positive!"); } _L = coordinates.getCoordinate(coordinates.Space.getAxisIndex(LossCutoff_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); SetMetricValue(LossCutoff_PROPERTYNAME, _L); if (_L < 0.0) { throw new Exception("Loss cutoff must be positive!"); } _TypeDouble = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Type_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); /* * double toss = SingletonRandomGenerator.Instance.NextDouble (); * * if (toss < _TypeDouble) { * _Type = -1; // play short * // Move myself in BlauSpace * coordinates.setCoordinate(coordinates.Space.getAxisIndex (Type_PROPERTYNAME), (double)0.0); * } else { * _Type = +1; // play long * // Move myself in BlauSpace * coordinates.setCoordinate(coordinates.Space.getAxisIndex (Type_PROPERTYNAME), (double)1.0); * } */ /* * if (this.ID % 2 == 0) _Type = -1; // play short * else _Type = +1; // play long */ SetMetricValue(Type_PROPERTYNAME, _Type); _clock = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Clock_PROPERTYNAME)); SetMetricValue(Clock_PROPERTYNAME, _clock); ResetMetrics(); _burninResetCompleted = false; _startTime = 0.0; //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have iniitialized TotalTrades metric to: "+GetMetricValue(TotalTrades_METRICNAME)); }
public void set(IBlauPoint p, double val) { IBlauPoint qp = Lattice.quantize(p); if (_evaluationData.ContainsKey(qp)) { throw new Exception("Duplicate assignment for the same IBlauPoint in BlauSpaceEvaluation"); } else { _evaluationData.Add(qp, val); } }
public Agent0x1(IBlauPoint coordinates, IAgentFactory creator, int id) : base(coordinates, creator, id, 0.0) { SingletonLogger.Instance().InfoLog(typeof(Agent0x1), "creating agent " + id); _aggressiveness = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Aggressiveness_PROPERTYNAME)); SetMetricValue(Aggressiveness_PROPERTYNAME, _aggressiveness); SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I am " + this.ID + " have set my aggressiveness to: " + GetMetricValue(Aggressiveness_PROPERTYNAME)); SetMetricValue(TotalTrades_METRICNAME, 0.0); SetMetricValue(NetWorth_METRICNAME, 0.0); SetMetricValue(TotalOrders_METRICNAME, 0.0); validateMetrics(7); SingletonLogger.Instance().InfoLog(typeof(Agent0x1), "done creating agent " + id); }
// create an agent public IAgent create() { if (LoggerDiags.Enabled) { SingletonLogger.Instance().InfoLog(typeof(AbstractAgentFactory), "AbstractAgentFactory sampling a BlauPoint..."); } IBlauPoint pt = _dist.getSample(); if (LoggerDiags.Enabled) { SingletonLogger.Instance().InfoLog(typeof(AbstractAgentFactory), "AbstractAgentFactory done sampling, chose: " + pt); } // dynamic ID allocation return(create(pt, this, -1)); }
// quantize a blaupoint with respect to this lattice public IBlauPoint quantize(IBlauPoint p) { if (p.Space != this.BlauSpace) { throw new Exception("BlauSpaceLattice is being requested to quantize a BlauPoint which lies in a foreign BlauSpace"); } IBlauPoint qp = new QuantizedBlauPoint(p.Space, this); for (int i = 0; i < p.Space.Dimension; i++) { double px = p.getCoordinate(i); // qp will quantize coordinates to this lattice qp.setCoordinate(i, px); } return(qp); }
public Agent0x2(IBlauPoint coordinates, IAgentFactory creator, int id) : base(coordinates, creator, id, 0.0) { _aggressiveness = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Aggressiveness_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my aggressiveness to: "+_aggressiveness); SetMetricValue(Aggressiveness_PROPERTYNAME, _aggressiveness); _optimism = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Optimism_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); SetMetricValue(Optimism_PROPERTYNAME, _optimism); _myTrades = 0; SetMetricValue(TotalTrades_METRICNAME, (double)_myTrades); _myOrders = 0; SetMetricValue(TotalOrders_METRICNAME, (double)_myOrders); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have iniitialized TotalTrades metric to: "+GetMetricValue(TotalTrades_METRICNAME)); }
private void advance() { if (_parmSpaceIterator.hasNext()) { //SingletonLogger.Instance().DebugLog(typeof(DistributionSpaceIterator), "_parmSpaceIterator.hasNext: true"); _parms = _parmSpaceIterator.next(); //SingletonLogger.Instance().DebugLog(typeof(DistributionSpaceIterator), "_parmSpaceIterator.next: "+parms); FillTemplateDistributionParameters(_parms); //SingletonLogger.Instance().DebugLog(typeof(DistributionSpaceIterator), "_templateDistribution: "+_templateDistribution); } else { //SingletonLogger.Instance().DebugLog(typeof(DistributionSpaceIterator), "_parmSpaceIterator.hasNext: false"); _templateDistribution = null; //SingletonLogger.Instance().DebugLog(typeof(DistributionSpaceIterator), "_templateDistribution: null"); } }
public void set(IBlauPoint p, double val) { IBlauPoint qp = Lattice.quantize(p); LinkedList <IScore> bin = null; if (_evaluationData.ContainsKey(qp)) { bin = _evaluationData[qp]; } else { bin = new LinkedList <IScore>(); _evaluationData.Add(qp, bin); } bin.AddLast(new Score(p, val)); }
public void BlauPointComparerTest() { Console.WriteLine("BlauPointComparerTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 200.0, 300.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); IBlauPoint bp = new BlauPoint(s); bp.setCoordinate(0, 10.0); bp.setCoordinate(1, 20.0); bp.setCoordinate(2, 30.0); IBlauPoint bp2 = bp.clone(); Dictionary <IBlauPoint, int> dic = new Dictionary <IBlauPoint, int>(new BlauPointComparer()); dic.Add(bp, 1); Assert.AreEqual(dic.ContainsKey(bp), true); Assert.AreEqual(dic.ContainsKey(bp2), true); Assert.Throws <System.ArgumentException>(delegate { dic.Add(bp2, 2); }); Assert.AreEqual(dic.Count, 1); Assert.AreEqual(dic[bp], 1); Assert.AreEqual(dic[bp2], 1); Dictionary <IBlauPoint, int> dic2 = new Dictionary <IBlauPoint, int>(new BlauPointComparer()); dic2.Add(bp2, 2); Assert.AreEqual(dic2.ContainsKey(bp2), true); Assert.AreEqual(dic2.ContainsKey(bp), true); Assert.Throws <System.ArgumentException>(delegate { dic.Add(bp, 1); }); Assert.AreEqual(dic2.Count, 1); Assert.AreEqual(dic2[bp], 2); Assert.AreEqual(dic2[bp2], 2); }
public AgentZx0(IBlauPoint coordinates, IAgentFactory creator, int id) : base(coordinates, creator, id, 0.0) { _clock = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Clock_PROPERTYNAME)); SetMetricValue(Clock_PROPERTYNAME, _clock); _priceOffset = coordinates.getCoordinate(coordinates.Space.getAxisIndex(PriceOffset_PROPERTYNAME)); SetMetricValue(PriceOffset_PROPERTYNAME, _priceOffset); _volumeOffset = coordinates.getCoordinate(coordinates.Space.getAxisIndex(VolumeOffset_PROPERTYNAME)); SetMetricValue(VolumeOffset_PROPERTYNAME, _volumeOffset); _myTrades = 0; SetMetricValue(AgentTrades_METRICNAME, (double)_myTrades); _myOrders = 0; SetMetricValue(AgentOrders_METRICNAME, (double)_myOrders); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have iniitialized TotalTrades metric to: "+GetMetricValue(TotalTrades_METRICNAME)); }
public override IBlauPoint getSample() { if (!_completed) { throw new Exception("Attempt to sample from Product distribution that has not been completed"); } IBlauPoint p = new BlauPoint(this.SampleSpace); foreach (IDistribution d in _factor) { IBlauPoint q = d.getSample(); for (int i = 0; i < q.Space.Dimension; i++) { p.setCoordinate(p.Space.getAxisIndex(q.Space.getAxis(i).Name), q.getCoordinate(i)); } } return(p); }
public void Distribution_Gaussian1DTest() { Console.WriteLine("Distribution_Gaussian1DTest"); double mean = 70.0; double std = 1.0; IDistribution d = create1DGaussian(mean, std); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "distribution: " + d); for (int i = 0; i < 1000; i++) { IBlauPoint p = d.getSample(); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "=> " + p); double diff = Math.Abs(p.getCoordinate(0) - mean); Assert.AreEqual((diff > 5.0 * std), false); } }
public void Distribution_Gaussian2DTest() { Console.WriteLine("Distribution_Gaussian2DTest"); double mean = 70.0; double std = 1.0; double mean2 = 20.0; double std2 = 1.0; IDistribution g2d = create2DGaussian(mean, std, mean2, std2); for (int i = 0; i < 100; i++) { IBlauPoint p = g2d.getSample(); SingletonLogger.Instance().DebugLog(typeof(Main_dist), "=> " + p); Assert.AreEqual((Math.Abs(p.getCoordinate(0) - mean) > 10.0 * std), false); Assert.AreEqual((Math.Abs(p.getCoordinate(1) - mean2) > 10.0 * std2), false); } }
// clone an agent public virtual IAgent cloneAgent(IAgent orig) { if (orig.Creator != this) { throw new Exception("Only the creator of an Agent may clone it!"); } // clone point IBlauPoint pt = orig.Coordinates.clone(); // explicit ID allocation IAgent dupe = create(pt, this, orig.ID); // duplicate metrics foreach (string metricName in orig.GetMetrics()) { dupe.SetMetricValue(metricName, orig.GetMetricValue(metricName)); } return(dupe); }
public Agent0xA(IBlauPoint coordinates, IAgentFactory creator, int id) : base(coordinates, creator, id, 0.0) { _G = coordinates.getCoordinate(coordinates.Space.getAxisIndex(GainCutoff_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my aggressiveness to: "+_aggressiveness); SetMetricValue(GainCutoff_PROPERTYNAME, _G); if (_G < 0.0) { throw new Exception("Gain cutoff must be positive!"); } _L = coordinates.getCoordinate(coordinates.Space.getAxisIndex(LossCutoff_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); SetMetricValue(LossCutoff_PROPERTYNAME, _L); if (_L < 0.0) { throw new Exception("Loss cutoff must be positive!"); } _TypeDouble = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Type_PROPERTYNAME)); //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have set my optimism to: "+_optimism); if (_TypeDouble < 0.0) { _Type = -1; // play short } else { _Type = +1; // play long } SetMetricValue(Type_PROPERTYNAME, _Type); _clock = coordinates.getCoordinate(coordinates.Space.getAxisIndex(Clock_PROPERTYNAME)); SetMetricValue(Clock_PROPERTYNAME, _clock); ResetMetrics(); _burninResetCompleted = false; _startTime = 0.0; //SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I have iniitialized TotalTrades metric to: "+GetMetricValue(TotalTrades_METRICNAME)); }
public void BlauSpaceIteratorManualTest() { Console.WriteLine("BlauSpaceIteratorManualTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); SingletonLogger.Instance().DebugLog(typeof(blau_tests), "=> " + s); int STEPS = 10; int[] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++) { STEPSarray[j] = STEPS; } IBlauSpaceIterator bsi = new BlauSpaceIterator(s, STEPSarray); int count = 0; int expected = (STEPS + 1) * (STEPS + 1) * (STEPS + 1); while (bsi.hasNext()) { IBlauPoint bp = (IBlauPoint)bsi.next(); Assert.IsInstanceOf(typeof(QuantizedBlauPoint), bp); SingletonLogger.Instance().DebugLog(typeof(blau_tests), "=> " + bp); count++; } Assert.AreEqual(count, expected); }
public void AddToBlauSpaceMultiEvaluation(IBlauSpaceMultiEvaluation bse) { if (!bse.Name.Equals(this.Name)) { throw new Exception("Attempt to AddToBlauSpaceEvaluation with two incompatible AgentEvaluation/IBlauSpaceEvaluation"); } // Console.WriteLine("XXX bse.Lattice "+bse.Lattice); foreach (IAgent ag in _evaluationData.Keys) { IBlauPoint p = ag.Coordinates; IBlauPoint pq = bse.Lattice.quantize(p); // Console.WriteLine("XXX p.dim:"+p.Space.Dimension+" pq.dim:"+pq.Space.Dimension+" bse.Lattice.dim:"+bse.Lattice.BlauSpace.Dimension); // Console.WriteLine("XXX pt "+p+" ==Q==> "+pq); double val = _evaluationData[ag]; bse.set(pq, val); } }
public Agent1x0(IBlauPoint coordinates, IAgentFactory creator, int id, double lambda, double gamma, double burnin) : base(coordinates, creator, id, burnin) { SingletonLogger.Instance().InfoLog(typeof(Agent1x0), "creating agent "+id); _clock = coordinates.getCoordinate( coordinates.Space.getAxisIndex(Clock_PROPERTYNAME) ); _aggressiveness = coordinates.getCoordinate( coordinates.Space.getAxisIndex(Aggressiveness_PROPERTYNAME) ); _patience = coordinates.getCoordinate( coordinates.Space.getAxisIndex(Patience_PROPERTYNAME) ); _trendiness = coordinates.getCoordinate( coordinates.Space.getAxisIndex(Trendiness_PROPERTYNAME) ); _optimism = coordinates.getCoordinate( coordinates.Space.getAxisIndex(Optimism_PROPERTYNAME) ); _riskiness = coordinates.getCoordinate( coordinates.Space.getAxisIndex(Riskiness_PROPERTYNAME) ); SetMetricValue(Clock_PROPERTYNAME, _clock); SetMetricValue(Aggressiveness_PROPERTYNAME, _aggressiveness); SetMetricValue(Patience_PROPERTYNAME, _patience); SetMetricValue(Trendiness_PROPERTYNAME, _trendiness); SetMetricValue(Optimism_PROPERTYNAME, _optimism); SetMetricValue(Riskiness_PROPERTYNAME, _riskiness); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" have set my clock to: "+GetMetricValue(Clock_PROPERTYNAME)); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" have set my aggressiveness to: "+GetMetricValue(Aggressiveness_PROPERTYNAME)); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" have set my patience to: "+GetMetricValue(Patience_PROPERTYNAME)); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" have set my trendiness to: "+GetMetricValue(Trendiness_PROPERTYNAME)); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" have set my optimism to: "+GetMetricValue(Optimism_PROPERTYNAME)); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" have set my riskiness to: "+GetMetricValue(Riskiness_PROPERTYNAME)); ResetMetrics(); _haveOrder = false; _lastBidVolume = 0.0; _lastAskVolume = 0.0; _lambda = lambda; _gamma = gamma; _burninResetCompleted = false; _startTime = 0.0; SingletonLogger.Instance().InfoLog(typeof(Agent1x0), "done creating agent "+id); }
// constructor protected AbstractAgent(IBlauPoint coordinates, IAgentFactory creator, int id, double burnin) { _coordinates = coordinates; _creator = creator; _burnin = burnin; // implicit assignment, allocates the ID dynamically if (id < 0) { // dynamic assignment _id = _nextID; _nextID++; } else { // explicit assignment (used in cloning, for example) _id = id; } // the ecosystem, initially null _sim = null; // the metrics associated with this Agent _metrics = new Dictionary <string, double>(); // the list of open orders _orders = new List <IOrder>(); // basic stats that every Agent maintains SetMetricValue(NumBids_METRICNAME, 0.0); SetMetricValue(NumAsks_METRICNAME, 0.0); SetMetricValue(Holdings_METRICNAME, 0.0); // boot message this.Send(this, new ActionPrompt(), GetTimeToNextActionPrompt()); if (LoggerDiags.Enabled) { SingletonLogger.Instance().InfoLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " Constructed @ " + Scheduler.GetTime()); } }
public void Distribution_Interval1DTest() { Console.WriteLine("Distribution_Interval1DTest"); int dim = 1; string [] names = new string [1] { "x" }; double [] mins = new double [1] { 0.00 }; double [] maxs = new double [1] { 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); double min = 10.0; double max = 30.0; IDistribution d = new Distribution_Interval(s, min, max); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "distribution: " + d); for (int i = 0; i < 1000; i++) { IBlauPoint p = d.getSample(); SingletonLogger.Instance().DebugLog(typeof(dist_tests), "=> " + p); for (int x = 0; x < dim; x++) { double diff = p.getCoordinate(x) - min; Assert.AreEqual(diff < 0.0, false); diff = max - p.getCoordinate(x); Assert.AreEqual(diff < 0.0, false); } } }
public override IBlauPoint getSample() { if (DETERMINISTIC_MODE) { IBlauPoint p = getSample(SampleNumber, TotalSamples); incrementSampleNumber(); return(p); } if (!_completed) { throw new Exception("Attempt to sample from Mixture distribution that has not been completed"); } IDistribution d = null; double val = SingletonRandomGenerator.Instance.NextDouble(); SingletonLogger.Instance().DebugLog(typeof(Mixture), "toss: " + val); double total = 0.0; foreach (MixtureComponent mc in _component) { IDistribution dx = mc.Distribution; double w = mc.Weight; total += w; if (total > val) { d = dx; break; } } return(d.getSample()); }