public void CalculateTest(double value, double expected) { var calculator = new Logarithm(); var actualResult = calculator.SingleCalculate(value); Assert.AreEqual(expected, actualResult, 0.0001); }
public void CalculateTest() { IOneArgumentCalculator calculator = new Logarithm(); double result = calculator.Calculate(1); Assert.AreEqual(0, result, 0.01); }
public void CalculatorTest(double firstValue, double expected) { var calculator = new Logarithm(); var actualResult = calculator.Calculate(firstValue); Assert.AreEqual(expected, actualResult); }
/// <summary> /// Simple log image filter. Applies the <see cref="System.Math.Log(double)"/> /// function for each pixel in the image, clipping values as needed. /// <para>Accord.NET internal call. Please see: <see cref="Accord.Imaging.Filters.Logarithm"/> for details.</para> /// </summary> /// <typeparam name="TColor">Color type.</typeparam> /// <param name="img">Image.</param> /// <param name="inPlace">Apply in place or not. If it is set to true return value can be omitted.</param> /// <returns>Processed image.</returns> public static TColor[,] Logarithm <TColor>(this TColor[,] img, bool inPlace = false) where TColor : struct, IColor { Logarithm l = new Logarithm(); return(img.ApplyFilter(l, inPlace)); }
public void CalculateTest(double arOne, double arTwo, double expected) { var calculator = new Logarithm(); var actualResult = calculator.Calculate(arOne, arTwo); Assert.AreEqual(expected, actualResult, 0.001); }
/// <summary> /// Simple log image filter. Applies the <see cref="System.Math.Log(double)"/> /// function for each pixel in the image, clipping values as needed. /// <para>Accord.NET internal call. Please see: <see cref="Accord.Imaging.Filters.Logarithm"/> for details.</para> /// </summary> /// <typeparam name="TColor">Color type.</typeparam> /// <typeparam name="TDepth">Channel type.</typeparam> /// <param name="img">Image.</param> /// <param name="inPlace">Apply in place or not. If it is set to true return value can be omitted.</param> /// <returns>Processed image.</returns> public static Image <TColor, TDepth> Logarithm <TColor, TDepth>(this Image <TColor, TDepth> img, bool inPlace = false) where TColor : IColor where TDepth : struct { Logarithm l = new Logarithm(); return(img.ApplyFilter(l, inPlace)); }
private int IterationNumber(double C, Vector <double> e, double delta) { Logarithm lg = it => Math.Log(it, 10); var absMaxE = e.Clone().Map(Math.Abs).Max(); var iterationNumber = (lg(absMaxE) - lg(delta) - lg(1 - C)) / lg(C) - 1; return((int)Math.Abs(Math.Round(iterationNumber))); }
public void Logarithm_Smoke_Test() { Assert.AreEqual(3, Logarithm.CalcBase2LogFloor(9)); Assert.AreEqual(3, Logarithm.CalcBase2LogFloor(8)); Assert.AreEqual(5, Logarithm.CalcBase2LogFloor(32)); Assert.AreEqual(2, Logarithm.CalcBase10LogFloor(102)); Assert.AreEqual(3, Logarithm.CalcBase10LogFloor(1000)); }
public void RunLogarithmTest() { var logarithm = new Logarithm(); var strategy = new Context <double>(logarithm); var result = strategy.Calculate(64.00, 2.00); Console.WriteLine($"log base(2) of 64 = {result}"); Assert.AreEqual(6.00, result); }
static void Main() { Stopwatch watch = new Stopwatch(); // SQRT Console.WriteLine("SQRT:"); watch.Restart(); Sqrt.FloatSqrt(1f, 10000000f, 1f); watch.Stop(); Console.WriteLine("Float: " + watch.ElapsedMilliseconds); watch.Restart(); Sqrt.DoubleSqrt(1d, 10000000d, 1d); watch.Stop(); Console.WriteLine("Double: " + watch.ElapsedMilliseconds); watch.Restart(); Sqrt.DecimalSqrt(1m, 10000000m, 1m); watch.Stop(); Console.WriteLine("Decimal: " + watch.ElapsedMilliseconds); // Sinus Console.WriteLine("Sinus:"); watch.Restart(); Sinus.FloatSinus(1f, 10000000f, 1f); watch.Stop(); Console.WriteLine("Float: " + watch.ElapsedMilliseconds); watch.Restart(); Sinus.DoubleSinus(1d, 10000000d, 1d); watch.Stop(); Console.WriteLine("Double: " + watch.ElapsedMilliseconds); watch.Restart(); Sinus.DecimalSinus(1m, 10000000m, 1m); watch.Stop(); Console.WriteLine("Decimal: " + watch.ElapsedMilliseconds); // Logarithm Console.WriteLine("Logarithm:"); watch.Restart(); Logarithm.FloatLogarithm(1f, 10000000f, 1f); watch.Stop(); Console.WriteLine("Float: " + watch.ElapsedMilliseconds); watch.Restart(); Logarithm.DoubleLogarithm(1d, 10000000d, 1d); watch.Stop(); Console.WriteLine("Double: " + watch.ElapsedMilliseconds); watch.Restart(); Logarithm.DecimalLogarithm(1m, 10000000m, 1m); watch.Stop(); Console.WriteLine("Decimal: " + watch.ElapsedMilliseconds); }
public override BaseExpression VisitLogarithm(Logarithm logarithm) { // log_a(x) -> 1 / (x ln(a)) var x = logarithm.Argument; var a = logarithm.Base; return(new Division( lhs: Real.One, rhs: new Multiplication( x, new Logarithm(Real.E, a) ) )); }
public void ApplyTest() { Bitmap input = Properties.Resources.lena_color; Logarithm log = new Logarithm(); Bitmap output = log.Apply(input); Exponential exp = new Exponential(); Bitmap reconstruction = exp.Apply(output); //ImageBox.Show("input", input); //ImageBox.Show("output", output); //ImageBox.Show("reconstruction", reconstruction); }
public void ProcessImageTest() { double[,] diag = Matrix.Magic(5); Bitmap input; new MatrixToImage(0, 100).Convert(diag, out input); Logarithm log = new Logarithm(); Bitmap output = log.Apply(input); Exponential exp = new Exponential(); Bitmap reconstruction = exp.Apply(output); double[,] actual; new ImageToMatrix(0, 100).Convert(reconstruction, out actual); double[,] expected = diag; Assert.IsTrue(expected.IsEqual(actual, 1.5)); }
public Node <INode> GetNode(string nodeName) { switch (nodeName) { case Absolute.NAME: INode nodeAbsolute = new Absolute() as INode; return(new Node <INode>(nodeAbsolute)); case Approx.NAME: INode nodeAprox = new Approx() as INode; return(new Node <INode>(nodeAprox)); case ArcCos.NAME: INode nodeArcCos = new ArcCos() as INode; return(new Node <INode>(nodeArcCos)); case ArcSin.NAME: INode nodeArcSin = new ArcSin() as INode; return(new Node <INode>(nodeArcSin)); case ArcTan2.NAME: INode nodeArcTan2 = new ArcTan2() as INode; return(new Node <INode>(nodeArcTan2)); case Ceil.NAME: INode nodeCeil = new Ceil() as INode; return(new Node <INode>(nodeCeil)); case CeilToInt.NAME: INode nodeCeilToInt = new CeilToInt() as INode; return(new Node <INode>(nodeCeilToInt)); case Clamp.NAME: INode nodeClamp = new Clamp() as INode; return(new Node <INode>(nodeClamp)); case Clamp01.NAME: INode nodeClamp01 = new Clamp01() as INode; return(new Node <INode>(nodeClamp01)); case ClosestPowerOf2.NAME: INode nodeClosestPowerOf2 = new ClosestPowerOf2() as INode; return(new Node <INode>(nodeClosestPowerOf2)); case Cosinus.NAME: INode nodeCosinus = new Cosinus() as INode; return(new Node <INode>(nodeCosinus)); case DeltaAngle.NAME: INode nodeDeltaAngle = new DeltaAngle() as INode; return(new Node <INode>(nodeDeltaAngle)); case Exp.NAME: INode nodeExp = new Exp() as INode; return(new Node <INode>(nodeExp)); case Floor.NAME: INode nodeFloor = new Floor() as INode; return(new Node <INode>(nodeFloor)); case FloorToInt.NAME: INode nodeFloorToInt = new FloorToInt() as INode; return(new Node <INode>(nodeFloorToInt)); case Lerp.NAME: INode nodeLerp = new Lerp() as INode; return(new Node <INode>(nodeLerp)); case LerpAngle.NAME: INode nodeLerpAngle = new LerpAngle() as INode; return(new Node <INode>(nodeLerpAngle)); case Log10.NAME: INode nodeLog10 = new Log10() as INode; return(new Node <INode>(nodeLog10)); case Logarithm.NAME: INode nodeLogarithm = new Logarithm() as INode; return(new Node <INode>(nodeLogarithm)); case Sinus.NAME: INode nodeSinus_ = new Sinus() as INode; return(new Node <INode>(nodeSinus_)); case Max.NAME: INode nodeMax = new Max() as INode; return(new Node <INode>(nodeMax)); case Min.NAME: INode nodeMin = new Min() as INode; return(new Node <INode>(nodeMin)); case MoveTowards.NAME: INode nodeMoveTowards = new MoveTowards() as INode; return(new Node <INode>(nodeMoveTowards)); case MoveTowardsAngle.NAME: INode nodeMoveTowardsAngle = new MoveTowardsAngle() as INode; return(new Node <INode>(nodeMoveTowardsAngle)); case NextPowerOfTwo.NAME: INode nodeNextPowerOfTwo = new NextPowerOfTwo() as INode; return(new Node <INode>(nodeNextPowerOfTwo)); case PerlinNoise.NAME: INode nodePerlinNoise = new PerlinNoise() as INode; return(new Node <INode>(nodePerlinNoise)); case PingPong.NAME: INode nodePingPong = new PingPong() as INode; return(new Node <INode> (nodePingPong)); case Pow.NAME: INode nodePow = new Pow() as INode; return(new Node <INode>(nodePow)); case SquareRoot.NAME: INode nodeSqrt = new SquareRoot() as INode; return(new Node <INode>(nodeSqrt)); case Tan.NAME: INode nodeTan = new Tan() as INode; return(new Node <INode>(nodeTan)); case Random.NAME: INode nodeRandom = new Random() as INode; return(new Node <INode>(nodeRandom)); default: return(null); } }
public void Statistics_Log2() { Assert.AreEqual(Logarithm.Log2(2), 1); Assert.AreEqual(Logarithm.Log2(1), 0); }
/// <summary> /// Function expression /// </summary> /// <param name="context"></param> /// <returns></returns> public override Function VisitFunction(CalculatorParser.FunctionContext context) { Function res = null; //Trigonometric functions if (FunctionMap[context.fun.Type] is Sinus) { res = new Sinus(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is Cosinus) { res = new Cosinus(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is Tangens) { res = new Tangens(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is Cotangens) { res = new Cotangens(Visit(context.expr())); } //Elementary functions if (FunctionMap[context.fun.Type] is Sqrt) { res = new Sqrt(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is Logarithm) { res = new Logarithm(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is Exponenta) { res = new Exponenta(Visit(context.expr())); } //Inverse Trigonometric functions if (FunctionMap[context.fun.Type] is ArcSinus) { res = new ArcSinus(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is ArcCosinus) { res = new ArcCosinus(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is ArcTangens) { res = new ArcTangens(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is ArcCotangens) { res = new ArcCotangens(Visit(context.expr())); } //Hyperbolic functions if (FunctionMap[context.fun.Type] is HypSinus) { res = new HypSinus(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is HypCosinus) { res = new HypCosinus(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is HypTangens) { res = new HypTangens(Visit(context.expr())); } if (FunctionMap[context.fun.Type] is HypCotangens) { res = new HypCotangens(Visit(context.expr())); } return(res); }
public void ErrorTest() { var calculator = new Logarithm(); Assert.Throws <Exception>(() => calculator.Calculate(0)); }
public void NegativeCalculateTest() { var calculator = new Logarithm(); Assert.Throws <System.Exception>(() => calculator.Calculate(-4, 1)); }
public void LogTest() { Assert.AreEqual(2, Logarithm.Log(10, 100)); }
private void Initialize(IEnumerable <string> variableNames, int nConstants) { #region symbol declaration var add = new Addition(); var sub = new Subtraction(); var mul = new Multiplication(); var div = new Division(); var mean = new Average(); var log = new Logarithm(); var pow = new Power(); var square = new Square(); var root = new Root(); var sqrt = new SquareRoot(); var exp = new Exponential(); // we use our own random number generator here because we assume // that grammars are only initialized once when setting the grammar in the problem. // This means everytime the grammar parameter in the problem is changed // we initialize the constants to new values var rand = new MersenneTwister(); // warm up for (int i = 0; i < 1000; i++) { rand.NextDouble(); } var constants = new List <Constant>(nConstants); for (int i = 0; i < nConstants; i++) { var constant = new Constant(); do { var constVal = rand.NextDouble() * 20.0 - 10.0; constant.Name = string.Format("{0:0.000}", constVal); constant.MinValue = constVal; constant.MaxValue = constVal; constant.ManipulatorSigma = 0.0; constant.ManipulatorMu = 0.0; constant.MultiplicativeManipulatorSigma = 0.0; } while (constants.Any(c => c.Name == constant.Name)); // unlikely, but it could happen that the same constant value is sampled twice. so we resample if necessary. constants.Add(constant); } var variables = new List <HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>(); foreach (var variableName in variableNames) { var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); variableSymbol.Name = variableName; variableSymbol.WeightManipulatorMu = 0.0; variableSymbol.WeightManipulatorSigma = 0.0; variableSymbol.WeightMu = 1.0; variableSymbol.WeightSigma = 0.0; variableSymbol.MultiplicativeWeightManipulatorSigma = 0.0; variableSymbol.AllVariableNames = new[] { variableName }; variableSymbol.VariableNames = new[] { variableName }; variables.Add(variableSymbol); } #endregion AddSymbol(add); AddSymbol(sub); AddSymbol(mul); AddSymbol(div); AddSymbol(mean); AddSymbol(log); AddSymbol(pow); AddSymbol(square); AddSymbol(root); AddSymbol(sqrt); AddSymbol(exp); constants.ForEach(AddSymbol); variables.ForEach(AddSymbol); #region subtree count configuration SetSubtreeCount(add, 2, 2); SetSubtreeCount(sub, 2, 2); SetSubtreeCount(mul, 2, 2); SetSubtreeCount(div, 2, 2); SetSubtreeCount(mean, 2, 2); SetSubtreeCount(log, 1, 1); SetSubtreeCount(pow, 2, 2); SetSubtreeCount(square, 1, 1); SetSubtreeCount(root, 2, 2); SetSubtreeCount(sqrt, 1, 1); SetSubtreeCount(exp, 1, 1); constants.ForEach((c) => SetSubtreeCount(c, 0, 0)); variables.ForEach((v) => SetSubtreeCount(v, 0, 0)); #endregion var functions = new ISymbol[] { add, sub, mul, div, mean, log, pow, root, square, sqrt }; var terminalSymbols = variables.Concat <ISymbol>(constants); var allSymbols = functions.Concat(terminalSymbols); #region allowed child symbols configuration foreach (var s in allSymbols) { AddAllowedChildSymbol(StartSymbol, s); } foreach (var parentSymb in functions) { foreach (var childSymb in allSymbols) { AddAllowedChildSymbol(parentSymb, childSymb); } } #endregion }
private void Initialize() { var add = new Addition(); var sub = new Subtraction(); var mul = new Multiplication(); var div = new Division(); var mean = new Average(); var sin = new Sine(); var cos = new Cosine(); var tan = new Tangent(); var log = new Logarithm(); var exp = new Exponential(); var @if = new IfThenElse(); var gt = new GreaterThan(); var lt = new LessThan(); var and = new And(); var or = new Or(); var not = new Not(); var constant = new Constant(); constant.MinValue = -20; constant.MaxValue = 20; variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); var allSymbols = new List <Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol }; var unaryFunctionSymbols = new List <Symbol>() { sin, cos, tan, log, exp, not }; var binaryFunctionSymbols = new List <Symbol>() { gt, lt }; var functionSymbols = new List <Symbol>() { add, sub, mul, div, mean, and, or }; foreach (var symb in allSymbols) { AddSymbol(symb); } foreach (var funSymb in functionSymbols) { SetSubtreeCount(funSymb, 1, 3); } foreach (var funSymb in unaryFunctionSymbols) { SetSubtreeCount(funSymb, 1, 1); } foreach (var funSymb in binaryFunctionSymbols) { SetSubtreeCount(funSymb, 2, 2); } SetSubtreeCount(@if, 3, 3); SetSubtreeCount(constant, 0, 0); SetSubtreeCount(variableSymbol, 0, 0); // allow each symbol as child of the start symbol foreach (var symb in allSymbols) { AddAllowedChildSymbol(StartSymbol, symb, 0); } // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0) foreach (var parent in allSymbols) { for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) { foreach (var child in allSymbols) { AddAllowedChildSymbol(parent, child, i); } } } }
public void ExceptionLessThanZeroTest(double firstArgument) { var calculator = new Logarithm(); Assert.Throws <Exception>(() => calculator.Calculate(firstArgument)); }
public abstract BaseExpression VisitLogarithm(Logarithm logarithm);
private void Use_count(object sender, RoutedEventArgs e) { Logarithm answ = new Logarithm(TBa.Text, TBb.Text); answer.Content = answ.getLogarithm(); }