public void Simple() { var vector = new VectorN(2); Assert.AreEqual(2, vector.DimensionCount); }
/// <summary> /// Draws the chart. /// </summary> public void DrawChart() { // Read fresh data from database. string readPlotableSql = string.Format(@" SELECT X, Y, Z1, Z2, Z3, Z4 FROM ai_plotable_unnormalized_data WHERE DataId = {0} AND OrdinalId = {1};" , _dataId, _ordinalId); List <VectorN> vectors = new List <VectorN>(10000); // initialized to 10,000 units. i.e. 100X100 Form1.ReadSql((MySqlDataReader msdr, MySqlCommand cmd) => { while (msdr.Read()) { VectorN tempVector = new VectorN( new double[] { Convert.ToDouble(msdr["X"]), Convert.ToDouble(msdr["Z" + _zNumber]), Convert.ToDouble(msdr["Y"]) }); vectors.Add(tempVector); } }, readPlotableSql); // Take a list of vectors, and plot them! ChartArea chartArea1 = new ChartArea(); List <Series> seriesSet = new List <Series>(100); //this.chart1 = new Chart(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.SuspendLayout(); chart1.ChartAreas["Default"].Area3DStyle.Enable3D = true; chart1.ChartAreas["Default"].Area3DStyle.IsRightAngleAxes = false; chart1.ChartAreas["Default"].Area3DStyle.Inclination = 40; chart1.ChartAreas["Default"].Area3DStyle.Rotation = 20; chart1.ChartAreas["Default"].Area3DStyle.WallWidth = 10; chart1.ChartAreas["Default"].Area3DStyle.LightStyle = LightStyle.Realistic; chart1.ChartAreas["Default"].Area3DStyle.PointDepth = 100; //chartArea1.Name = "Default"; //this.chart1.ChartAreas.Add(chartArea1); //this.chart1.Location = new System.Drawing.Point(12, 12); //this.chart1.Name = "chart1"; int size = 100; double min = 100000; double max = 0; // adds 100 series! for (int i = 0; i < size; i++) { seriesSet.Add(new Series()); seriesSet[i].ChartArea = "Default"; seriesSet[i].Name = "" + i; for (int j = 0; j < size; j++) { if (vectors.Count > j + i * size) { double normalized = vectors[j + i * size][1]; seriesSet[i].Points.AddXY(j, normalized); if (normalized > max) { max = normalized; } if (normalized < min) { min = normalized; } } } for (int j = 0; j < size; j++) { if (vectors.Count > j + i * size) { double normalized = seriesSet[i].Points[j].YValues[0]; double diff = max - min; // total is 255, we need to find scaling factor. double redRange = ((normalized - min) / diff) * 200; //red range! double greenRange = ((normalized - min) / diff) * 100; //red range! seriesSet[i].Points[j].Color = Color.FromArgb((int)redRange, 0, 0); } } seriesSet[i].Legend = "Legend1"; seriesSet[i].ChartType = SeriesChartType.Line; //seriesSet[i].Color = Color.FromArgb(100-i, i, 0); // Set point labels //seriesSet[i].IsValueShownAsLabel = true; this.chart1.Series.Add(seriesSet[i]); } // this.chart1.Size = new System.Drawing.Size(1319, 720); this.chart1.TabIndex = 0; ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); this.ResumeLayout(false); this.Refresh(); }
/// <summary> /// Measure the body at the new point in time, update its velocity, /// and then calculate its reach again. /// </summary> /// <param name="time">Time.</param> /// <param name="newVelocity">New velocity.</param> public void SetVelocity(float time, VectorN newVelocity) { Remeasure(time); velocity = newVelocity; RecalculateReach(); }
/// <summary> /// Measure the body at the new point in time, update its acceleration, /// and then calculate its reach again. /// </summary> /// <param name="time">Time.</param> /// <param name="newAcceleration">New acceleration.</param> public void SetAcceleration(float time, VectorN newAcceleration) { Remeasure(time); acceleration = newAcceleration; RecalculateReach(); }
/// <summary> /// Multiplication technique to be used. Perceptron should use simple /// sclar vector multiplication while winnow and kernel methods should /// use variants /// </summary> /// <param name="v1">First vector</param> /// <param name="v2">Second vector</param> /// <returns></returns> protected virtual double Mult(VectorN v1, VectorN v2) { return v1 * v2; }
/// <summary> /// Generates the new chart. Is used to query data and plot the 3D chart. /// </summary> /// <param name="axisX">The axis x.</param> /// <param name="axisY">The axis y.</param> public void GenerateNewChart(int axisX, int axisY) { // First get the new max Id from the datatable. int maxDataId = 0; int maxOrdinalId = 0; double toleranceLevel = 0; this.chart1.Series.Clear(); string readCmd = string.Format(@" SELECT DataId, ToleranceLevel, AxisX, AxisY, OrdinalId FROM ai_plotset WHERE AxisX = {0} AND AxisY = {1} ORDER BY DataId DESC, OrdinalId DESC LIMIT 1; " , axisX, axisY); ReadSql((MySqlDataReader msdr, MySqlCommand cmd) => { if (msdr.Read() && !Convert.IsDBNull(msdr["DataId"])) { maxDataId = Convert.ToInt32(msdr["DataId"]); toleranceLevel = Convert.ToDouble(msdr["ToleranceLevel"]); maxOrdinalId = Convert.ToInt32(msdr["OrdinalId"]); } }, readCmd); _dataId = maxDataId; _ordinalId = maxOrdinalId; _axisX = axisX; _axisY = axisY; // Read fresh data from database. string readPlotableSql = @"SELECT X,Y,Z FROM ai_plotable_data WHERE DataId = " + maxDataId + " AND OrdinalId = " + maxOrdinalId + ";"; List <VectorN> vectors = new List <VectorN>(10000); // initialized to 10,000 units. i.e. 100X100 ReadSql((MySqlDataReader msdr, MySqlCommand cmd) => { while (msdr.Read()) { VectorN tempVector = new VectorN( new double[] { Convert.ToDouble(msdr["X"]), Convert.ToDouble(msdr["Y"]), Convert.ToDouble(msdr["Z"]) }); vectors.Add(tempVector); } }, readPlotableSql); // Take a list of vectors, and plot them! ChartArea chartArea1 = new ChartArea(); List <Series> seriesSet = new List <Series>(100); //this.chart1 = new Chart(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.SuspendLayout(); chart1.ChartAreas["Default"].Area3DStyle.Enable3D = true; chart1.ChartAreas["Default"].Area3DStyle.IsRightAngleAxes = false; chart1.ChartAreas["Default"].Area3DStyle.Inclination = 40; chart1.ChartAreas["Default"].Area3DStyle.Rotation = 20; chart1.ChartAreas["Default"].Area3DStyle.WallWidth = 10; chart1.ChartAreas["Default"].Area3DStyle.LightStyle = LightStyle.Realistic; chart1.ChartAreas["Default"].Area3DStyle.PointDepth = 100; //chartArea1.Name = "Default"; //this.chart1.ChartAreas.Add(chartArea1); //this.chart1.Location = new System.Drawing.Point(12, 12); //this.chart1.Name = "chart1"; int size = 100; double min = 100000; double max = 0; // adds 100 series! for (int i = 0; i < size; i++) { seriesSet.Add(new Series()); seriesSet[i].ChartArea = "Default"; seriesSet[i].Name = "" + i; for (int j = 0; j < size; j++) { if (vectors.Count > j + i * size) { double normalized = vectors[j + i * size][1]; seriesSet[i].Points.AddXY(j, normalized); if (normalized > max) { max = normalized; } if (normalized < min) { min = normalized; } } } for (int j = 0; j < size; j++) { if (vectors.Count > j + i * size) { double normalized = seriesSet[i].Points[j].YValues[0]; double diff = max - min; // total is 255, we need to find scaling factor. double redRange = ((normalized - min) / diff) * 50; //red range! double greenRange = ((normalized - min) / diff) * 100; //red range! seriesSet[i].Points[j].Color = Color.FromArgb((int)redRange, (int)greenRange, 0); } } seriesSet[i].Legend = "Legend1"; seriesSet[i].ChartType = SeriesChartType.Line; //seriesSet[i].Color = Color.FromArgb(100-i, i, 0); // Set point labels //seriesSet[i].IsValueShownAsLabel = true; this.chart1.Series.Add(seriesSet[i]); } // this.chart1.Size = new System.Drawing.Size(1319, 720); this.chart1.TabIndex = 0; ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); this.ResumeLayout(false); this.Refresh(); }
public void ExceptionZero() { Assert.Throws <ArgumentOutOfRangeException>(() => VectorN.GetZeroVector(0)); }
public void ExceptionLeftNull() { var vector1 = new VectorN(2); IVector <double> vector = null / vector1; }
public void ExceptionDifferentDimensions() { var vector2D1 = new Vector2D(); VectorBase <double> vectorBase = new VectorN(4); var matrix = vector2D1 * vectorBase; }
public IHttpActionResult SearchForProjections([FromBody] dynamic Parameters) { int RVisitorID = Parameters.RVisitorID; float Latitude = Parameters.Latitude; float Longitude = Parameters.Longitude; bool GPSAquired = Parameters.GPSAquired; string searchQuery = Parameters.SearchQuery; var CinemaDistances = new Dictionary <int, float>(); var CinemaIDs = new List <int>(); int CinemaID = 0; if (GPSAquired) { foreach (var cinema in principal.CinemaCoordinates.Where(x => !x.Cinemas.IsDeleted).ToList()) { var vectorTarget = new VectorN(new float[] { (float)cinema.Latitude, (float)cinema.Longitude }); var vectorMe = new VectorN(new float[] { Latitude, Longitude }); CinemaDistances.Add(cinema.CinemaID, VectorN.Subtraction(vectorMe, vectorTarget).GetLength()); } CinemaID = CinemaDistances.OrderBy(x => x.Value).Select(y => y.Key).FirstOrDefault(); CinemaIDs.Add(CinemaID); } else { CinemaIDs.AddRange(principal.Cinemas.Where(x => !x.IsDeleted).Select(x => x.CinemaID).ToList()); } var recommendedProjections = new List <Projections>(); if (String.IsNullOrWhiteSpace(searchQuery)) { var recommendedMovies = GetRecommendedMovies(RVisitorID).Result; var projections = principal.Projections .Where(x => !x.IsDeleted && DbFunctions.TruncateTime(x.DateTimeStart) > DbFunctions.TruncateTime(DateTime.Today) && CinemaIDs.Contains(x.CinemaHalls.Cinemas.CinemaID)) .OrderBy(x => x.Movies.Name) .DistinctBy(x => x.MovieID) .ToList(); foreach (var movieID in recommendedMovies) { var projection = projections.Where(x => x.MovieID == movieID); if (projection.Any()) { recommendedProjections.Add(projection.FirstOrDefault()); } } foreach (var projection in recommendedProjections) { projections.Remove(projection); } recommendedProjections.AddRange(projections); } else { List <string> Movies = principal.Projections .Where(x => !x.IsDeleted && DbFunctions.TruncateTime(x.DateTimeStart) > DbFunctions.TruncateTime(DateTime.Today) && CinemaIDs.Contains(x.CinemaHalls.Cinemas.CinemaID)) .OrderBy(x => x.Movies.Name) .DistinctBy(x => x.Movies.Name) .Select(x => x.Movies.Name + "$" + x.Movies.Synopsis) .ToList(); Movies.ContextSort(searchQuery); foreach (var movie in Movies) { string s = movie.Split('$')[0]; recommendedProjections.AddRange(principal.Projections.Where(x => !x.IsDeleted && DbFunctions.TruncateTime(x.DateTimeStart) > DbFunctions.TruncateTime(DateTime.Today) && CinemaIDs.Contains(x.CinemaHalls.Cinemas.CinemaID) && x.Movies.Name == s).OrderBy(x => x.Movies.Name) .DistinctBy(x => x.Movies.Name).ToList()); } } return(Ok(recommendedProjections.Select(x => new { Duration = x.Movies.DurationInMinutes.ToString(), Age = x.Movies.AgeRestrictions.Name, Release = x.Movies.ReleaseYear.ToString(), MovieName = x.Movies.Name, x.MovieID, x.CinemaHallID, x.DateTimeStart, x.TicketPrice, MovieCover = Convert.ToBase64String(x.Movies.PictureBytes), Projections = principal.Projections .Where(y => DbFunctions.TruncateTime(y.DateTimeStart) > DbFunctions.TruncateTime(DateTime.Today) && y.Movies.MovieID == x.Movies.MovieID && !y.IsDeleted && CinemaIDs.Contains(y.CinemaHalls.Cinemas.CinemaID)) .OrderBy(y => y.DateTimeStart).Select(y => new { y.ProjectionID, y.MovieID, y.CinemaHallID, y.DateTimeStart, y.TechnologyTypes.Name, y.TicketPrice, CinemaHallName = y.CinemaHalls.Name, CinemaName = y.CinemaHalls.Cinemas.Name, }).Take(10) }).ToList())); }
public static bool Orthogonal(VectorN v1, VectorN v2) { return(VectorN.DotProduct(v1, v2) == 0); }
public void ExceptionNegative() { VectorN.GetZeroVector(-1); }
public void ExceptionZero() { VectorN.GetZeroVector(0); }
public void ExceptionDifferentDimensions() { var vector3D = new Vector3D(); VectorBase <double> vectorBase = new VectorN(4); IVector <double> vector = vector3D - vectorBase; }
public void ExceptionNegative() { Assert.Throws <ArgumentOutOfRangeException>(() => VectorN.GetZeroVector(-1)); }
public void ExceptionDifferentDimensions() { var vector1 = new VectorN(2); var vector2 = new VectorN(4); IVector <double> vector = vector1 / vector2; }
public static Vector <double> VectorNToMathNet(VectorN point) { double[] components = new double[point.Components.Count]; point.Components.CopyTo(components); return(Vector <double> .Build.DenseOfArray(components)); }
public void ExceptionRightNull() { var vector1 = new VectorN(2); IVector <double> vector = vector1 / null; }
/// <summary> /// Measure the body at the new point in time, update its position, /// and then calculate its reach again. /// </summary> /// <param name="time">Time.</param> /// <param name="newPosition">New position.</param> public void SetPosition(float time, VectorN newPosition) { Remeasure(time); position = newPosition; RecalculateReach(); }
/// <summary> /// Adds a new w vector to the perceptron and initialises all /// the values in the vector to 0 /// </summary> /// <param name="size">size of the vector to add</param> private void AddNewLabel( int size ) { VectorN w = new VectorN(size); for (int i = 0; i < w.Length; i++) w[i] = 0; W.Add(w); }
protected override double Mult(VectorN v1, VectorN v2) { return Math.Exp(v1 * v2); }