public void Test_LDA_Performance2000_var(int rep) { int errorCode = 0; try { LDA lda = new LDA(); ILArray <double> X = ILMath.horzcat(ILMath.randn(2, 2000) * 2.0, ILMath.randn(2, 2000) * -2.0); ILLogicalArray labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1, 2000), ILMath.zeros(1, 2000))); labels = labels.Concat(ILMath.tological(ILMath.zeros(1, 2000).Concat(ILMath.ones(1, 2000), 1)), 0); ILPerformer timer = new ILPerformer(); LDA.Hyperplane C; int oldRefMin = ILNumerics.Settings.ILSettings.MinimumRefDimensions; ILNumerics.Settings.ILSettings.MinimumRefDimensions = 2; timer.Tic(); for (int i = 0; i < rep; i++) { C = lda.TrainLDA(X, labels, 0.4); } timer.Toc(); Info("Test_LDA_Performance: with reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms"); ILNumerics.Settings.ILSettings.MinimumRefDimensions = 3; timer.Tic(); for (int i = 0; i < rep; i++) { C = lda.TrainLDA(X, labels, 0.4); } timer.Toc(); ILNumerics.Settings.ILSettings.MinimumRefDimensions = oldRefMin; Info("Test_LDA_Performance: without reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms"); Success(); }catch (Exception e) { Error(errorCode, e.Message); } }
//protected static bool isempty(string str) //{ // return (str == string.Empty); //} protected static double randn() { //get { return((double)(ILMath.randn())); } }
private void Test_SortSpeed(int length) { try { ILArray <double> ResILN = null, ResCLR = null, A = null; long durILN = 0, durCLR = 0; Misc.ILPerformer p = new ILNumerics.Misc.ILPerformer(); for (int i = 0; i < 10; i++) { A = ILMath.randn(length, 1); p.Tic(); ILMath.sort(A); p.Toc(); durILN += p.Duration; ResCLR = A.C; p.Tic(); Array.Sort(ResCLR.m_data); p.Toc(); durCLR += p.Duration; } ResILN = ILMath.sort(A); if (!ResCLR.Equals(ResILN)) { throw new Exception("invalid values!"); } Info(String.Format("ILNumerics.Net sort {1} needed: {0}ms", durILN / 10, A.Dimensions.ToString())); Info(String.Format("CLR Array.Sort {1} needed: {0}ms", durCLR / 10, A.Dimensions.ToString())); // descending durCLR = 0; durILN = 0; IComparer comparer = new DescComparerDouble(); for (int i = 0; i < 10; i++) { A = ILMath.randn(length, 1); p.Tic(); ResILN = ILMath.sort(A, true); p.Toc(); durILN += p.Duration; ResCLR = A.C; p.Tic(); Array.Sort(ResCLR.m_data, comparer); p.Toc(); durCLR += p.Duration; } if (!ResCLR.Equals(ResILN)) { throw new Exception("invalid values!"); } Info(String.Format("ILNumerics.Net sort {1} desc, needed: {0}ms", durILN / 10, A.Dimensions.ToString())); Info(String.Format("CLR Array.Sort {1} desc, needed: {0}ms", durCLR / 10, A.Dimensions.ToString())); } catch (Exception e) { Error(0, e.Message); } }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray <long> tmp; ret[count++] = ILArray <long> .empty(0, 0); ret[count++] = ILArray <long> .empty(1, 0); ret[count++] = ILArray <long> .empty(0, 1, 0); // scalar ret[count++] = (ILArray <long>)(long) 1; ret[count++] = (ILArray <long>)(long) int.MaxValue; ret[count++] = (ILArray <long>)(long) int.MinValue; ret[count++] = (ILArray <long>)(long) 0; ret[count++] = (ILArray <long>)(long)(-30); // vector ret[count++] = ILMath.toint64(ILMath.zeros(1, 10)); ret[count++] = ILMath.toint64(ILMath.ones(1, 10)); ret[count++] = ILMath.toint64(ILMath.zeros(10, 1)); ret[count++] = ILMath.toint64(ILMath.ones(10, 1)); ret[count++] = ILMath.toint64(ILMath.vector(0.0, 10.0)); ret[count++] = ILMath.toint64(ILMath.vector(-5.0, 4.0)); tmp = ILMath.toint64(ILMath.vector(-5.0, 4.0)); tmp[0] = int.MinValue; tmp["end"] = int.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.toint64(ILMath.zeros(3, 2)); ret[count++] = ILMath.toint64(ILMath.rand(2, 4)); ret[count++] = ILMath.toint64(ILMath.ones(2, 3)); ret[count++] = ILMath.toint64(ILMath.ones(3, 2)); // 3d array ret[count++] = ILMath.toint64(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.toint64(ILMath.toint32(0.0 / (ILMath.randn(4, 3, 2)))); ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2) * int.MinValue); ret[count++] = ILMath.toint64(ILMath.rand(4, 3, 2) * int.MaxValue); // 4d array ret[count++] = ILMath.toint64(ILMath.rand(30, 2, 3, 20) * int.MaxValue); return(ret); }
private void Form1_Load(object sender, EventArgs e) { m_panel = ILPanel.Create(); Controls.Add(m_panel); ILArray <double> data = ILMath.randn(1, 100); m_bars = new ILBarGraph2D(m_panel, data); m_bars.BarWidth = 0.001f; m_panel.Graphs.AddPlot(m_bars); m_panel.Legend.Visible = true; m_timer = new Timer(); m_timer.Tick += new EventHandler(m_timer_Tick); m_timer.Interval = 100; m_timer.Start(); m_lastTickCount = Environment.TickCount; }
public void Test_LDA_Performance200k_10() { int errorCode = 0; try { LDA lda = new LDA(); ILArray <double> X = ILMath.horzcat(ILMath.randn(2, 200000) * 2.0, ILMath.randn(2, 200000) * -2.0); ILLogicalArray labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1, 100000), ILMath.zeros(1, 100000))); labels = labels.Concat(ILMath.tological(ILMath.zeros(1, 100000).Concat(ILMath.ones(1, 100000), 1)), 0); ILPerformer timer = new ILPerformer(); timer.Tic(); LDA.Hyperplane C; for (int i = 0; i < 10; i++) { C = lda.TrainLDA(X, labels, 0.4); } timer.Toc(); Info("Test_LDA_Performance2: data: 2x200000 run 10 times in: " + timer.Duration + "ms"); Success(); }catch (Exception e) { Error(errorCode, e.Message); } }
private void SetExampleScene(ILPanel panel) { ILScene scene = new ILScene(); try { ILLabel.DefaultFont = new System.Drawing.Font("Helvetica", 8); //ilPanel1.Driver = RendererTypes.GDI; #region upper left plot // prepare some data ILArray <float> P = 1, x = ILMath.linspace <float>(-2, 2, 40), y = ILMath.linspace <float>(2, -2, 40); ILArray <float> F = ILMath.meshgrid(x, y, P); // a simple RBF ILArray <float> Z = ILMath.exp(-(1.2f * F * F + P * P)); // surface expects a single matrix Z[":;:;2"] = F; Z[":;:;1"] = P; // add a plot cube var pc = scene.Add(new ILPlotCube { // shrink viewport to upper left quadrant ScreenRect = new RectangleF(0.05f, 0, 0.4f, 0.5f), // 3D rotation TwoDMode = false, Children = { // add surface new ILSurface(Z) { // disable mouse hover marking Fill = { Markable = false }, Wireframe ={ Markable = false }, // make it shiny UseLighting = true, Children = { new ILColorbar() } }, //ILLinePlot.CreateXPlots(Z["1:10;:;0"], markers: new List<MarkerStyle>() { // MarkerStyle.None,MarkerStyle.None,MarkerStyle.None,MarkerStyle.None,MarkerStyle.Circle, MarkerStyle.Cross, MarkerStyle.Plus, MarkerStyle.TriangleDown }), //new ILLegend("hi","n","ku","zs","le", "blalblalblalblalb\\color{red} hier gehts rot") }, Rotation = Matrix4.Rotation(new Vector3(1.1f, -0.4f, -0.69f), 1.3f) }); #endregion #region top right plot // create a gear shape var gear = new ILGear(toothCount: 30, inR: 0.5f, outR: 0.9f) { Fill = { Markable = false, Color = Color.DarkGreen } }; // group with right clipping plane var clipgroup = new ILGroup() { Clipping = new ILClipParams() { Plane0 = new Vector4(1, 0, 0, 0) }, Children = { // a camera holding the (right) clipped gear new ILCamera() { // shrink viewport to upper top quadrant ScreenRect = new RectangleF(0.5f, 0, 0.5f, 0.5f), // populate interactive changes back to the global scene IsGlobal = true, // adds the gear to the camera Children ={ gear }, Position = new Vector3(0, 0, -15) } } }; // setup the scene var gearGroup = scene.Add(new ILGroup { clipgroup, clipgroup // <- second time: group is cloned }); gearGroup.First <ILCamera>().Parent.Clipping = new ILClipParams() { Plane0 = new Vector4(-1, 0, 0, 0) }; // make the left side transparent green gearGroup.First <ILTriangles>().Color = Color.FromArgb(100, Color.Green); // synchronize both cameras; source: left side gearGroup.First <ILCamera>().PropertyChanged += (s, arg) => { gearGroup.Find <ILCamera>().ElementAt(1).CopyFrom(s as ILCamera, false); }; #endregion #region left bottom plot // start value int nrBalls = 10; bool addBalls = true; var balls = new ILPoints("balls") { Positions = ILMath.tosingle(ILMath.randn(3, nrBalls)), Colors = ILMath.tosingle(ILMath.rand(3, nrBalls)), Color = null, Markable = false }; var leftBottomCam = scene.Add(new ILCamera { ScreenRect = new RectangleF(0, 0.5f, 0.5f, 0.5f), Projection = Projection.Perspective, Children = { balls } }); // funny label string harmony = @"\color{red}H\color{blue}a\color{green}r\color{yellow}m\color{magenta}o\color{cyan}n\color{black}y\reset "; var ballsLabel = scene.Add(new ILLabel(tag: "harmony") { Text = harmony, Fringe = { Color = Color.FromArgb(240, 240, 240) }, Position = new Vector3(-0.75f, -0.25f, 0) }); long oldFPS = 1; PointF currentMousePos = new PointF(); // setup the swarm. Start with a few balls, increase number // until framerate drops below 60 fps. ILArray <float> velocity = ILMath.tosingle(ILMath.randn(3, nrBalls)); EventHandler <ILRenderEventArgs> updateBallsRenderFrame = (s, arg) => { // transform viewport coords into 3d scene coords Vector3 mousePos = new Vector3(currentMousePos.X * 2 - 1, currentMousePos.Y * -2 + 1, 0); // framerate dropped? -> stop adding balls if (panel.FPS < oldFPS && panel.FPS < 60) { addBalls = false; } oldFPS = panel.FPS; Computation.UpdateBalls(mousePos, balls, velocity, addBalls); // balls buffers have been changed -> must call configure() to publish balls.Configure(); // update balls label ballsLabel.Text = harmony + "(" + balls.Positions.DataCount.ToString() + " balls)"; }; // saving the mouse position in MouseMove is easier for // transforming the coordinates into the viewport leftBottomCam.MouseMove += (s, arg) => { // save the mouse position currentMousePos = arg.LocationF; }; panel.BeginRenderFrame += updateBallsRenderFrame; m_cleanUpExample = () => { leftBottomCam.MouseMove -= (s, arg) => { // save the mouse position currentMousePos = arg.LocationF; }; panel.BeginRenderFrame -= updateBallsRenderFrame; }; #endregion panel.Scene = scene; } catch (Exception exc) { System.Diagnostics.Trace.WriteLine("ILPanel_Load Error:"); System.Diagnostics.Trace.WriteLine("===================="); System.Diagnostics.Trace.WriteLine(exc.ToString()); MessageBox.Show(exc.ToString()); } }
protected static ILArray <double> randn(int dim1, int dim2) { return(ILMath.randn(dim1, dim2)); }