/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //basicEffect = Content.Load<Effect>("specular"); basicEffect = Content.Load <Effect>("diffuse"); var graph = SampleGenerator.CreateVoronoiGraph(1000, 30000, 2, 23); var vertices = graph.Paint3D(new VertexPositionColorNormalFactory()); var normal = new Vector3(0, -1, 0); meshTriangles = vertices.Count / 3; vertices.Add(new VertexPositionColorNormal(Vector3.Zero, Color.Red, normal)); vertices.Add(new VertexPositionColorNormal(new Vector3(1.15f, 0, 0), Color.Red, normal)); vertices.Add(new VertexPositionColorNormal(Vector3.Zero, Color.Green, normal)); vertices.Add(new VertexPositionColorNormal(new Vector3(0, 1.15f, 0), Color.Green, normal)); vertices.Add(new VertexPositionColorNormal(Vector3.Zero, Color.Blue, normal)); vertices.Add(new VertexPositionColorNormal(new Vector3(0, 0, 1.15f), Color.Blue, normal)); var rawVertices = vertices.ToArray(); terrain = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColorNormal), rawVertices.Length, BufferUsage.WriteOnly); terrain.SetData(rawVertices); // TODO: use this.Content to load your game content here }
public void TestWeight() { var classification = SampleGenerator.MakeClassification( nSamples: 200, nFeatures: 100, weights: new[] { 0.833, 0.167 }.ToList(), randomState: new Random(0)); var classWeight = ClassWeightEstimator <int> .Explicit(new Dictionary <int, double> { { 0, 5 } }); Matrix x = SparseMatrix.OfMatrix(classification.X); foreach (var clf in new IClassifier <int>[] { new LogisticRegression <int>(classWeightEstimator: classWeight), //new LinearSvc(classWeight:classWeight, random_state=0), //new Svc<int>(classWeight: classWeight) }) { clf.Fit(x.SubMatrix(0, 180, 0, x.ColumnCount), classification.Y.Take(180).ToArray()); var yPred = clf.Predict(x.SubMatrix(180, x.RowCount - 180, 0, x.ColumnCount)); var matchingN = yPred.Zip(classification.Y.Skip(180), Tuple.Create).Where(t => t.Item1 == t.Item2).Count(); Assert.IsTrue(matchingN >= 11); } }
public void TestImportances() { var classification = SampleGenerator.MakeClassification(nSamples: 200, nFeatures: 10, nInformative: 3, nRedundant: 0, nRepeated: 0, shuffle: false, randomState: new Random(13)); //var xstr = "[" + string.Join(",", classification.X.RowEnumerator().Select(r => "[" + string.Join(",", r.Item2) + "]")) + "]"; //var ystr = "[" + string.Join(",", classification.Y) + "]"; foreach (var name in CLF_TREES) { var clf = CreateClassifier <int>(name, random: new Random(0)); clf.Fit(classification.X, classification.Y); var importances = clf.FeatureImportances(); int n_important = importances.Where(v => v > 0.1).Count(); Assert.AreEqual(10, importances.Count, "Failed with {0}".Frmt(name)); Assert.AreEqual(3, n_important, "Failed with {0}".Frmt(name)); var X_new = clf.Transform(classification.X, threshold: ThresholdChoice.Mean()); Assert.IsTrue(0 < X_new.ColumnCount, "Failed with {0}".Frmt(name)); Assert.IsTrue(X_new.ColumnCount < classification.X.ColumnCount, "Failed with {0}".Frmt(name)); } }
public Mitchell2D(SampleGenerator g, int k = 5) { Generator = g; K = Math.Max(1, k); samples = new List <PointF>(); }
public void SomeCloneTests() { var event1 = SampleGenerator.GameEventTest1(); var event2 = event1.CloneJson(); Assert.AreEqual(event1.Properties.Count, event2.Properties.Count); Assert.AreEqual(event1.Properties["stat_kill_creepy"], event2.Properties["stat_kill_creepy"]); }
public string GetJson() { var sampleList = SampleGenerator.GenerateCustomSampleList(3050000, 0, 20); var json = JsonConvert.SerializeObject(sampleList); var size = Encoding.Unicode.GetByteCount(json); // just to check size return(json); }
public void Test3_IfSampleListCorrect() { var sampleList = SampleGenerator.GenerateCustomSampleList(400000, 1, 20); int qtyTotal = (from s in sampleList select s.Qty).Sum(); var result = ParallelExercise(sampleList); Assert.Equal(qtyTotal, result); }
public void Test3_Cancellation() { var sampleList = SampleGenerator.GenerateCustomSampleList(1000, 1, 10); long qtyTotal = (from s in sampleList select s.Qty).Sum(); var result = ParallelExercise(sampleList, true); // Assert: should fail and throw OperationCanceledException (check test explorer message) }
public void TwoVarsTreeOps() { var service = new SampleGenerator(2, 3, 0.001); var formula = service.GetFormula(); var noiseFormula = formula.Clone<INode>(); NoisyConstants(noiseFormula); var alg = new RegressionAlgorithm(noiseFormula, service.InSamples, service.ExactResult); alg.Run(); Assert.AreNotEqual(alg.GetResult(), null); }
public void Test3_OutOfRangeException() { var sampleList = SampleGenerator.GenerateCustomSampleList(1000, 20, 30); long qtyTotal = (from s in sampleList select s.Qty).Sum(); var result = ParallelExercise(sampleList); // Assert: should fail and throw ArgumentOutOfRangeException (check test explorer message) }
public void TestLiblinearRandomState() { var classification = SampleGenerator.MakeClassification(nSamples: 20); var lr1 = new LogisticRegression <int>(random: new Random(0)); lr1.Fit(classification.X, classification.Y); var lr2 = new LogisticRegression <int>(random: new Random(0)); lr2.Fit(classification.X, classification.Y); Assert.IsTrue(lr1.Coef.AlmostEquals(lr2.Coef)); }
public void DatacontractSerializerHelperTest() { var gameEvent = SampleGenerator.GameEventTestLarge(); var content = DatacontractSerializerHelper.Serialize(gameEvent); Assert.IsTrue(content.Length > 0); var gameEvent2 = DatacontractSerializerHelper.Deserialize <GameEvent>(content); Assert.AreEqual(gameEvent.Properties.Count, gameEvent2.Properties.Count); Assert.AreEqual(gameEvent.Properties["stat_22"], gameEvent2.Properties["stat_22"]); }
private void AudioCallback(IntPtr userData, IntPtr samples, int bufferSize) { unsafe { var span = new Span <byte>( samples.ToPointer(), bufferSize ); SampleGenerator.Invoke(span, Format); } }
public void Reset(SampleGenerator g = null, int k = 0) { if (g != null) { Generator = g; } if (k > 0) { K = k; } samples.Clear(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine("This is ..."); Console.WriteLine("The Voice Of The Station!"); Console.WriteLine("..."); Console.WriteLine("..."); Console.WriteLine("input datetime: 3pm 12 Dec 2018"); // ProcessADailyFile_SampleTEST(); // ProcessADailyFile_Sample1(); // ProcessFlowFile_SampleTEST(); // ProcessFlowFile_Sample1(); // ProcessFlowFile_Sample2(); // ProcessFlowFile_Sample3(); SampleGenerator sg = new SampleGenerator(); var dataset = sg.GenerateAPISample("03", null); Console.WriteLine("OUTPUT:"); Console.WriteLine(""); foreach (var data in dataset) { Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine("Year: " + data.Year); Console.WriteLine("Month: " + data.Month); Console.WriteLine("Day: " + data.Day); Console.WriteLine("Hour: " + data.Hour); Console.WriteLine("Minute: " + data.Minute); Console.WriteLine("Second: " + data.Second); Console.WriteLine("MilliSecond: " + data.MilliSecond); Console.WriteLine("UserId: " + data.UserId); Console.WriteLine("Latitude: " + data.Latitude); Console.WriteLine("Longitude: " + data.Longitude); Console.WriteLine("NeigbourhoodSize: " + data.NeigbourhoodSize); Console.WriteLine("AcceptableNeighbourhoodSize: " + data.AcceptableNeighbourhoodSize); Console.WriteLine("IsAcceptable: " + data.IsAcceptable); Console.WriteLine(" "); Console.WriteLine("IsHappyFace: " + data.IsHappyFace); Console.WriteLine(" "); Console.WriteLine(" "); } // Console.ReadKey(); Console.WriteLine("Hello World! AGAIN!"); }
public void Sinus100Hz_Spectrum() { //var audioContainer = AudioLoader.Load(Samples.Wave100hz); var container = SampleGenerator.GenerateSineSignalContainer(100, 2048, 2048); var fft = new FastFourierTransformCPU(container.Samples).CreateTransform(); var slice = FastFourierTransformCPU.ConvertToSpectrumSlice(fft); var amplitude50 = slice.GetAmplitudeForFrequency(50); var amplitude100 = slice.GetAmplitudeForFrequency(100); var amplitude150 = slice.GetAmplitudeForFrequency(150); Assert.True(amplitude50 < 0.1f); Assert.True(amplitude100 > 0.9f); Assert.True(amplitude150 < 0.1f); }
public void GameEventEncryptionTest() { CommonConfiguration.Instance.EncryptionConfiguration.IsEncryptionEnabled = true; CommonConfiguration.Instance.EncryptionConfiguration.Salt = "o6806642kbM7c5"; var event1 = SampleGenerator.GameEventTest1(); var packet = SampleGenerator.GamePacketTest1(); packet.GameEvent = event1; // is the content encrypted Assert.IsTrue(packet.Content.Contains("76561198024856042") == false); Assert.AreEqual(event1.Properties["stat_avg_level_1"], packet.GameEvent.Properties["stat_avg_level_1"]); }
static void Main() { var sampleGenerator = new SampleGenerator(2, 6, 0.001); var randomFormula = sampleGenerator.GetFormula(); Console.WriteLine("Formula before making constants noisy: {0}", randomFormula); GenerateNoisyConstantsForNodeLeafes(randomFormula); Console.WriteLine("Formula after making constants noisy: {0}", randomFormula); Console.WriteLine("Press any key to start regression..."); Console.ReadKey(true); var alg = new RegressionAlgorithm(randomFormula, sampleGenerator.InSamples, sampleGenerator.ExactResult); ConsoleGui.Run(alg, 5, ""); Console.WriteLine("Result: {0}", alg.GetResult()); }
public void Test1() { var sampleList1 = SampleGenerator.GenerateCustomSampleList(500000, 0, 20); var sampleList2 = SampleGenerator.GenerateSampleList2(); var newSampleList = (from s1 in sampleList1 join s2 in sampleList2 on s1.Id equals s2.Id select new Sample { Id = s1.Id, Content = s1.Content, Qty = s1.Qty }).ToList(); Assert.NotEmpty(newSampleList); }
public void TestMakeLowRankMatrix() { Matrix <double> x = SampleGenerator.MakeLowRankMatrix( numSamples: 50, numFeatures: 25, effectiveRank: 5, tailStrength: 0.01, randomState: new Random(0)); Assert.AreEqual(50, x.RowCount, "X shape mismatch"); Assert.AreEqual(25, x.ColumnCount, "X shape mismatch"); Svd svd = x.Svd(true); double sum = svd.S().Sum(); Assert.IsTrue(Math.Abs(sum - 5) < 0.1, "X rank is not approximately 5"); }
public void EncryptionTests() { CommonConfiguration.Instance.EncryptionConfiguration.IsEncryptionEnabled = true; CommonConfiguration.Instance.EncryptionConfiguration.Salt = "o6806642kbM7c5"; var sw = new Stopwatch(); sw.Start(); var value = SampleGenerator.GameEventTestLarge(); var p1 = sw.ElapsedMilliseconds; var serialised = JsonSerializerHelper.Serialize(value); var p2 = sw.ElapsedMilliseconds; var encrypted = GamePacket.EncryptStringAES(serialised); var p3 = sw.ElapsedMilliseconds; var dSerialisation = p2 - p1; var dEncryption = p3 - p2; }
private void LoadGen(Sf2Region region, AssetManager assets) { SampleDataAsset sda = assets.SampleAssetList[region.Generators[(int)GeneratorEnum.SampleID]]; SampleGenerator gen = new SampleGenerator(); gen.EndPhase = sda.End + region.Generators[(int)GeneratorEnum.EndAddressOffset] + 32768 * region.Generators[(int)GeneratorEnum.EndAddressCoarseOffset]; gen.Frequency = sda.SampleRate; gen.KeyTrack = region.Generators[(int)GeneratorEnum.ScaleTuning]; gen.LoopEndPhase = sda.LoopEnd + region.Generators[(int)GeneratorEnum.EndLoopAddressOffset] + 32768 * region.Generators[(int)GeneratorEnum.EndLoopAddressCoarseOffset]; switch (region.Generators[(int)GeneratorEnum.SampleModes] & 0x3) { case 0x0: case 0x2: gen.LoopMode = LoopModeEnum.NoLoop; break; case 0x1: gen.LoopMode = LoopModeEnum.Continuous; break; case 0x3: gen.LoopMode = LoopModeEnum.LoopUntilNoteOff; break; } gen.LoopStartPhase = sda.LoopStart + region.Generators[(int)GeneratorEnum.StartLoopAddressOffset] + 32768 * region.Generators[(int)GeneratorEnum.StartLoopAddressCoarseOffset]; gen.Offset = 0; gen.Period = 1.0; if (region.Generators[(int)GeneratorEnum.OverridingRootKey] > -1) { gen.RootKey = region.Generators[(int)GeneratorEnum.OverridingRootKey]; } else { gen.RootKey = sda.RootKey; } gen.StartPhase = sda.Start + region.Generators[(int)GeneratorEnum.StartAddressOffset] + 32768 * region.Generators[(int)GeneratorEnum.StartAddressCoarseOffset]; gen.Tune = (short)(sda.Tune + region.Generators[(int)GeneratorEnum.FineTune] + 100 * region.Generators[(int)GeneratorEnum.CoarseTune]); gen.VelocityTrack = 0; gen.Samples = sda.SampleData; this.genList[0] = gen; }
public void TestLinearRegressionSparseMultipleOutcome() { var random = new Random(0); var r = SampleGenerator.MakeSparseUncorrelated(random: random); Matrix x = SparseMatrix.OfMatrix(r.X); Vector <double> y = r.Y.Column(0); Matrix y1 = DenseMatrix.OfColumns(y.Count, 2, new[] { y, y }); int nFeatures = x.ColumnCount; var ols = new LinearRegression(); ols.Fit(x, y1); Assert.AreEqual(Tuple.Create(2, nFeatures), ols.Coef.Shape()); Assert.AreEqual(Tuple.Create(2, nFeatures), ols.Coef.Shape()); Matrix <double> yPred = ols.Predict(x); ols.Fit(x, y); Matrix <double> yPred1 = ols.Predict(x); Assert.IsTrue(yPred1.Column(0).AlmostEquals(yPred.Column(0))); Assert.IsTrue(yPred1.Column(0).AlmostEquals(yPred.Column(1))); }
public void TestMakeRegression() { var r = SampleGenerator.MakeRegression( numSamples: 100, numFeatures: 10, numInformative: 3, shuffle: false, effectiveRank: 5, coef: true, bias: 0.0, noise: 1.0, random: new Random(0)); Assert.AreEqual(Tuple.Create(100, 10), r.X.Shape(), "X shape mismatch"); Assert.AreEqual(Tuple.Create(100, 1), r.Y.Shape(), "y shape mismatch"); Assert.AreEqual(Tuple.Create(10, 1), r.Coef.Shape(), "coef shape mismatch"); Assert.AreEqual(3, r.Coef.Column(0).Count(v => v != 0), "Unexpected number of informative features"); // Test that y ~= np.dot(X, c) + bias + N(0, 1.0) Matrix <double> matrix = r.Y - (r.X * r.Coef); Assert.IsTrue(Math.Abs(matrix.Column(0).StandardDeviation() - 1.0) < 0.2); }
public void TestLinearRegressionMultipleOutcome() { var result = SampleGenerator.MakeRegression(shuffle: false, random: new Random(0)); Matrix y = DenseMatrix.OfColumns( result.Y.RowCount, 2, new[] { result.Y.Column(0), result.Y.Column(0) }); var numFeatures = result.X.RowCount; var clf = new LinearRegression(fitIntercept: true); clf.Fit(result.X, y); Assert.AreEqual(Tuple.Create(2, numFeatures), clf.Coef.Shape()); Matrix <double> yPred = clf.Predict(result.X); clf.Fit(result.X, result.Y); Matrix <double> yPred1 = clf.Predict(result.X); Assert.IsTrue(yPred1.Column(0).AlmostEquals(yPred.Column(0))); Assert.IsTrue(yPred1.Column(0).AlmostEquals(yPred.Column(1))); }
private void InitializiseSampleGenerator() { generator = new SampleGenerator(time, layer, filepath, volume); // we need to save this object in order to generate the storyboard when all parsing processes finished GlobalMemory.Instance.RegisterStoryboardGenerator(generator); }
static void Main(string[] args) { Bootstrapper.Initialize(); SampleGenerator.CreateVoronoiGraphAndSave(); }
public SamplesService(IUserService userService, IProfileService profileService, IPhotosService photosService, IConversationService conversationService, IVisitService visitService, IResourceService resourceService) { _generator = new SampleGenerator(profileService, userService, photosService, conversationService, visitService, resourceService); }