예제 #1
0
        double calculateStandardDeviation(List <DOUBLEPOINT> points, Coefficient coefficient)
        {
            double lfStandardDeviation = 0;

            int i;

            for (i = 0; i < points.Count; i++)
            {
                try
                {
                    checked
                    {
                        double calcY = coefficient.w * points[i].X + coefficient.b;
                        lfStandardDeviation += (calcY - points[i].Y) * (calcY - points[i].Y);
                    }
                }
                catch (Exception)
                {
                    break;
                }
            }

            if (i < points.Count)
            {
                lfStandardDeviation = double.MaxValue;
            }
            else
            {
                lfStandardDeviation /= points.Count;
                lfStandardDeviation  = Math.Sqrt(lfStandardDeviation);
            }

            return(lfStandardDeviation);
        }
예제 #2
0
        public IHttpActionResult PutCoefficient(Guid id, Coefficient coefficient)
        {
            if (!ModelState.IsValid || coefficient == null)
            {
                return(BadRequest(ModelState));
            }

            if (id != coefficient.Id)
            {
                return(BadRequest());
            }

            try
            {
                unitOfWork.Coefficients.Update(coefficient);
                unitOfWork.Complete();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CoefficientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void EditWentylatorInDB(Wentylator w)
        {
            using (var context = new DBContext())
            {
                Wentylator newWentylator = context.Wentylatory.Include(b => b.Nature).Include(c => c.Coefficients).First(wentylator => wentylator.ID == w.ID);
                newWentylator.Name       = w.Name;
                newWentylator.Power      = w.Power;
                newWentylator.Revolution = w.Revolution;
                newWentylator.NatureId   = w.NatureId;

                if (_excelExists)
                {
                    var oldCoefficients = context.Coefficients.Where(c => c.Wentylator.Name == newWentylator.Name);
                    foreach (var coef in oldCoefficients)
                    {
                        coef.IsArchived = true;
                    }
                    double[,] C = GetCoefficientsFromExcel(ref newWentylator);
                    for (int i = 0; i < C.GetLength(0); i++)
                    {
                        var coefficient = new Coefficient
                        {
                            Wentylator = newWentylator,
                            Level      = i,
                            Value      = C[i, 0]
                        };
                        context.Coefficients.Add(coefficient);
                    }
                }
                context.SaveChanges();
            }
        }
예제 #4
0
 static void Main(string[] args)
 {
     while (true)
     {
         Console.WriteLine("\n Please, give me two coefficients of linear equation a and b. \n Format: \"int32, int32\".");
         string      line = Console.ReadLine();
         Coefficient k    = new Coefficient();
         try
         {
             Parse(line, ref k.a, ref k.b);
             Console.WriteLine(k.a + "   " + k.b);
             break;
         }
         catch (FormatException e)
         {
             Console.WriteLine("The catch is: \"{0}\"", e.Message);
             continue;
         }
         finally
         {
             Console.WriteLine("By!");
         }
     }
     Console.ReadKey();
 }
예제 #5
0
        public override string ToString()
        {
            if (Variables.Count == 0)
            {
                return(Coefficient.ToString());
            }
            StringBuilder sb = new StringBuilder();

            if (Coefficient != 1)
            {
                if (Coefficient == -1)
                {
                    sb.Append('-');
                }
                else
                {
                    sb.Append(Coefficient);
                }
            }
            foreach (var variable in Variables)
            {
                sb.Append(variable.ToString());
            }
            return(sb.ToString());
        }
예제 #6
0
        public IHttpActionResult PostCoefficient(Coefficient coefficient)
        {
            if (!ModelState.IsValid || coefficient == null)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                unitOfWork.Coefficients.Add(coefficient);
                unitOfWork.Complete();
            }
            catch (DbUpdateException)
            {
                if (CoefficientExists(coefficient.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = coefficient.Id }, coefficient));
        }
예제 #7
0
        void Train(double digit, int endian)
        {
            calcResults.Clear();

            for (int idIndex = 0; idIndex < idClasses.Count; idIndex++)
            {
                IDCLASS idClass = idClasses[idIndex];
                if (idClass.framePoints.Count == 0)
                {
                    continue;
                }

                int dlc = idClass.framePoints[0].frameX.DataLen;
                for (int startIndex = 0; startIndex <= dlc - digit; startIndex++)
                {
                    List <DOUBLEPOINT> lfPoints = new List <DOUBLEPOINT>();

                    double lfX;
                    for (int f = 0; f < idClass.framePoints.Count; f++)
                    {
                        lfX = jointValue(idClass.framePoints[f].frameX, startIndex, Convert.ToInt32(Math.Floor(digit + 0.6)), endian);
                        lfPoints.Add(new DOUBLEPOINT(lfX, idClass.framePoints[f].lfY));
                    }

                    Coefficient coefficient = linearRegression(lfPoints);
                    double      sd          = calculateStandardDeviation(lfPoints, coefficient);
                    calcResults.Add(new CALCULATIONRESULT(idClass.id, startIndex, sd, coefficient, lfPoints));
                }
            }
        }
예제 #8
0
 public CALCULATIONRESULT(uint ID, int StartIndex, double SD, Coefficient Coef, List <DOUBLEPOINT> Points)
 {
     id                = ID;
     startIndex        = StartIndex;
     standardDeviation = SD;
     coefficient       = Coef;
     points            = Points;
 }
예제 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            Coefficient coefficient = db.Coefficients.Find(id);

            db.Coefficients.Remove(coefficient);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #10
0
        public bool UpdateCoefficient(Coefficient coefficient, SqlTransaction tran)
        {
            string sql = @"UPDATE  Coefficient
                    SET     CoefficientName = @CoefficientName ,
                            CoefficientContent = @CoefficientContent
                    WHERE   CoefficientID = @CoefficientID ";

            return(Excute(sql, coefficient, tran));
        }
예제 #11
0
        public override int GetHashCode()
        {
            int h1 = Coefficient.GetHashCode();
            int h2 = Radicand.GetHashCode();
            int h3 = (((h1 << 5) + h1) ^ h2);
            int h4 = Index.GetHashCode();

            return(((h3 << 5) + h3) ^ h4);
        }
예제 #12
0
        public IHttpActionResult GetCoefficient(Guid id)
        {
            Coefficient coefficient = unitOfWork.Coefficients.Get(id);

            if (coefficient == null)
            {
                return(NotFound());
            }

            return(Ok(coefficient));
        }
예제 #13
0
    // on double click in type 2 questions split
    // currently if you double click in the middle it glitches so fix that
    public void OnPointerClick(PointerEventData eventData)
    {
        Coefficient coef = this.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>();

        if (eventData.clickCount == 2 && coef != null && (typeOfItem == Draggable.Slot.Value || typeOfItem == Draggable.Slot.Variable))
        {
            if (coef.GetValue() > 1)
            {
                StartCoroutine(ShowSplit(coef.GetFractionValue() - 1));
            }
        }
    }
예제 #14
0
        public override XElement ToXElement()
        {
            XElement xe = new XElement(XElementName());

            xe.Add(new XAttribute("Name", Name));
            xe.Add(new XAttribute("Type", EntityType.ToString()));
            xe.Add(new XAttribute("P", Alignment.ToString()));
            xe.Add(new XAttribute("Size", BufferSize.ToString()));
            xe.Add(new XAttribute("Coeffi", Coefficient.ToString()));
            xe.Add(this.GetPropertiesXElement());
            return(xe);
        }
예제 #15
0
        public override string ToString()
        {
            var result = new List <string>();

            if (!Coefficient.Equals(NumberDecimal.One))
            {
                result.Add(Coefficient.ToString());
            }
            result.AddRange(Variables.Select(a => a.ToString()));
            result.AddRange(Others.Select(a => "(" + a.ToString() + ")"));
            return(string.Join("*", result));
        }
예제 #16
0
 public ActionResult Edit([Bind(Include = "ID,DifficultyId,MetricId,Value")] Coefficient coefficient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(coefficient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DifficultyId = new SelectList(db.Difficulties, "ID", "Name", coefficient.DifficultyId);
     ViewBag.MetricId     = new SelectList(db.Metrics, "ID", "Type", coefficient.MetricId);
     return(View(coefficient));
 }
예제 #17
0
        public override XElement ToXElement()
        {
            XElement xe = new XElement("Spot");

            xe.Add(new XAttribute("Name", Name));
            xe.Add(new XAttribute("Type", EntityType.ToString()));
            xe.Add(new XAttribute("Pos", Position.ToString()));
            xe.Add(new XAttribute("Rad", ServingRadius.ToString()));
            xe.Add(new XAttribute("Coeffi", Coefficient.ToString()));
            xe.Add(this.GetPropertiesXElement());
            return(xe);
        }
예제 #18
0
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append(Coefficient.ToString());

            foreach (var unknown in UnKnowns)
            {
                builder.Append(unknown.ToString());
            }

            return(builder.ToString());
        }
예제 #19
0
        public IHttpActionResult DeleteCoefficient(Guid id)
        {
            Coefficient coefficient = unitOfWork.Coefficients.Get(id);

            if (coefficient == null)
            {
                return(NotFound());
            }

            unitOfWork.Coefficients.Remove(coefficient);
            unitOfWork.Complete();

            return(Ok(coefficient));
        }
예제 #20
0
        public ActionResult Edit(Guid?id, Coefficient Collection, string ischeck)
        {
            Collection.IsTure = ischeck == "on" ? true : false;

            if (!ModelState.IsValid)
            {
                Edit(id);
                return(View(Collection));
            }
            _icoefficientService.Save(id, Collection);
            _icoefficientService.Commit();

            return(RedirectToAction("Index"));
        }
예제 #21
0
        // GET: Coefficients/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Coefficient coefficient = db.Coefficients.Find(id);

            if (coefficient == null)
            {
                return(HttpNotFound());
            }
            return(View(coefficient));
        }
예제 #22
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nEnter two " +
                              "coefficients of linear equation A and B." +
                              "\nFormat: \"A,B\".");
            string      line = Console.ReadLine();
            Coefficient k    = new Coefficient();

            Parse(line, ref k.A, ref k.B);
            Console.WriteLine($"\nResult:\n" +
                              $"{k.A}X + {k.B}Y = 0;");

            Console.ReadKey();
        }
예제 #23
0
파일: EcoCalc.cs 프로젝트: ZakMed/asms-md
        public static void EvalSums(Coefficient c, IEnumerable <IndicatorValue> ivs)
        {
            var re = new Regex(@"suma\(i\d+\)");
            var mc = re.Matches(c.Formula);

            foreach (Match mt in mc)
            {
                var sum = Convert.ToInt32(mt.Value.Replace("suma(i", string.Empty).Replace(")", string.Empty));

                c.Formula = c.Formula.Replace(mt.Value,
                                              ivs.Where(o => o.IndicatorId == sum)
                                              .Sum(o => o.Value).ToString(CultureInfo.InvariantCulture));
            }
        }
        void NormTerms()
        {
            var hamiltonian = new OrbitalIntegralHamiltonian();

            hamiltonian.AddRange(orbitalIntegrals.Select(o => (o, o.Coefficient.ToDoubleCoeff())));
            var oneNorm = hamiltonian.Norm();

            hamiltonian.AddRange(orbitalIntegrals.Select(o => (o, o.Coefficient.ToDoubleCoeff())));
            Assert.Equal(oneNorm * 2.0, hamiltonian.Norm());

            hamiltonian.AddRange(orbitalIntegrals.Select(o => (o, o.Coefficient.ToDoubleCoeff())));
            Assert.Equal(oneNorm * 3.0, hamiltonian.Norm());

            hamiltonian.AddRange(orbitalIntegrals.Select(o => (o, o.Coefficient.ToDoubleCoeff())));
            Assert.Equal(oneNorm * 4.0, hamiltonian.Norm());
        }
예제 #25
0
        // GET: Coefficients/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Coefficient coefficient = db.Coefficients.Find(id);

            if (coefficient == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DifficultyId = new SelectList(db.Difficulties, "ID", "Name", coefficient.DifficultyId);
            ViewBag.MetricId     = new SelectList(db.Metrics, "ID", "Type", coefficient.MetricId);
            return(View(coefficient));
        }
예제 #26
0
        public async Task <ServiceResponse <int> > GetPrice(string ticketType)
        {
            ServiceResponse <int> response    = new ServiceResponse <int>();
            ServiceResponse <int> rpcResponse = new ServiceResponse <int>();

            int userId = GetUserId();

            Enums.UserType userType = Enums.UserType.RegulerUser;
            try
            {
                if (userId != -1)
                {
                    // RPC call to account service to get user type
                    var res = await _rpcClient.CallAsync(userId.ToString());

                    Console.WriteLine("test1");
                    rpcResponse = System.Text.Json.JsonSerializer.Deserialize <ServiceResponse <int> >(res);
                    Console.WriteLine("test2");
                    if (rpcResponse.Success)
                    {
                        Console.WriteLine("test3");
                        userType = (Enums.UserType)rpcResponse.Data;
                    }
                    Console.WriteLine("test4");
                }
            }
            catch (Exception)
            {
                response.Message = "Possible discount couldn't be processed. Price shown is without discount.\n";
            }

            try
            {
                Enums.TicketType type          = (Enums.TicketType)Enum.Parse(typeof(Enums.TicketType), ticketType);
                PricelistItem    pricelistItem = await _context.PricelistItems.FirstOrDefaultAsync(pi => pi.Pricelist.Active == true && pi.Item.TicketType == type);

                Coefficient coef = await _context.Coefficients.FirstOrDefaultAsync(c => c.UserType == userType);

                response.Data = (int)Math.Round(pricelistItem.Price * coef.Value);
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Message = e.Message;
            }
            return(response);
        }
예제 #27
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(GlobalId != null ? GlobalId.ToStepValue() : "$");
            parameters.Add(OwnerHistory != null ? OwnerHistory.ToStepValue() : "$");
            parameters.Add(Name != null ? Name.ToStepValue() : "$");
            parameters.Add(Description != null ? Description.ToStepValue() : "$");
            parameters.Add(ObjectType != null ? ObjectType.ToStepValue() : "$");
            parameters.Add(PredefinedType.ToStepValue());
            parameters.Add(ActionType.ToStepValue());
            parameters.Add(ActionSource.ToStepValue());
            parameters.Add(Coefficient != null ? Coefficient.ToStepValue() : "$");
            parameters.Add(Purpose != null ? Purpose.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
예제 #28
0
        public int AddCoefficient(Coefficient coefficient, SqlTransaction tran)
        {
            string sql = @" INSERT  INTO dbo.Coefficient
                                    ( CoefficientName ,
                                      DeleteFlag ,
                                      CoefficientContent,
                                      Creator,
                                      CreateTime
                                    )
                            VALUES  ( @CoefficientName ,
                                      0 ,
                                      @CoefficientContent,
                                      @Creator,
                                      GetDate()
                                    )  SELECT @@IDENTITY ";

            return(ExcuteScalar(sql, coefficient, tran));
        }
예제 #29
0
        private static Coefficient[][] GenerateCoefficients(int termsCount, int varsCount)
        {
            var result = new Coefficient[termsCount][];

            for (var i = 0; i < result.Length; ++i)
            {
                result[i] = new Coefficient[TERM_SIZE];
                var indices = RandomInts(TERM_SIZE, varsCount);
                var values  = RandomDoubles(TERM_SIZE);
                for (var j = 0; j < TERM_SIZE; ++j)
                {
                    result[i][j].Index = indices[j];
                    result[i][j].Value = values[j];
                }
            }

            return(result);
        }
예제 #30
0
        Coefficient linearRegression(List <DOUBLEPOINT> points)
        {
            int         i;
            Coefficient coefficient = new Coefficient();

            double sumX = 0, averX, tmp;

            for (i = 0; i < points.Count; i++)
            {
                sumX += points[i].X;
            }
            averX = sumX / points.Count;

            tmp = 0;
            for (i = 0; i < points.Count; i++)
            {
                tmp += points[i].Y * (points[i].X - averX);
            }
            coefficient.w = tmp;

            tmp = 0;
            for (i = 0; i < points.Count; i++)
            {
                tmp += points[i].X * points[i].X;
            }
            tmp -= (sumX * sumX) / points.Count;

            coefficient.w /= tmp;
            if (double.IsNaN(coefficient.w))
            {
                coefficient.w = double.MaxValue;
                coefficient.b = points[0].Y;
                return(coefficient);
            }

            tmp = 0;
            for (i = 0; i < points.Count; i++)
            {
                tmp += (points[i].Y - coefficient.w * points[i].X);
            }
            coefficient.b = tmp / points.Count;

            return(coefficient);
        }
예제 #31
0
 /*-------------------------------------------------------------------------------------------------------------*/
 /** <summary>
  * Primary constructor. </summary>
  * <param name="follow"> The value for the coefficient for the follow rule </param>
  * <param name="cohesion"> The value for the coefficient for the cohesion rule </param>
  * <param name="separation"> The value for the coefficient for the separation rule </param> */
 public NormalVectorSet(float follow, float cohesion, float separation)
 {
     followCoefficient = new Coefficient(follow, "Follow");
     cohesionCoefficient = new Coefficient(cohesion, "Cohesion");
     separationCoefficient = new Coefficient(separation, "Separation");
 }
예제 #32
0
 public void IsEquivalentType_WhenTypesDifferent()
 {
     var firstCoef = new CoefAndGoals(0, 0);
     var secondCoef = new Coefficient(1);
     Assert.IsFalse(firstCoef.IsEquivalentType(secondCoef));
 }