Exemple #1
0
            public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
            {
                XYFunctionPlotItem s = (XYFunctionPlotItem)obj;

                info.AddValue("Data", s._plotData);
                info.AddValue("Style", s._plotStyles);
            }
Exemple #2
0
            /// <summary>
            /// Serializes XYColumnPlotItem Version 0.
            /// </summary>
            /// <param name="obj">The XYColumnPlotItem to serialize.</param>
            /// <param name="info">The serialization info.</param>
            /// <param name="context">The streaming context.</param>
            public void GetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            {
                XYFunctionPlotItem s = (XYFunctionPlotItem)obj;

                info.AddValue("Data", s._plotData);
                info.AddValue("Style", s._plotStyles);
            }
Exemple #3
0
            /// <summary>
            /// Deserializes the XYColumnPlotItem Version 0.
            /// </summary>
            /// <param name="obj">The empty XYColumnPlotItem object to deserialize into.</param>
            /// <param name="info">The serialization info.</param>
            /// <param name="context">The streaming context.</param>
            /// <param name="selector">The deserialization surrogate selector.</param>
            /// <returns>The deserialized XYColumnPlotItem.</returns>
            public object SetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISurrogateSelector selector)
            {
                XYFunctionPlotItem s = (XYFunctionPlotItem)obj;

                s._plotData   = (XYFunctionPlotData)info.GetValue("Data", typeof(XYColumnPlotData));
                s._plotStyles = (G2DPlotStyleCollection)info.GetValue("Style", typeof(G2DPlotStyleCollection));

                return(s);
            }
Exemple #4
0
        protected override void CopyFrom(PlotItem fromb)
        {
            base.CopyFrom(fromb);
            XYFunctionPlotItem from = fromb as XYFunctionPlotItem;

            if (from != null)
            {
                this.Data = from.Data;
            }
        }
Exemple #5
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                XYFunctionPlotData     pa = (XYFunctionPlotData)info.GetValue("Data", typeof(XYColumnPlotData));
                G2DPlotStyleCollection ps = (G2DPlotStyleCollection)info.GetValue("Style", typeof(G2DPlotStyleCollection));

                if (null == o)
                {
                    return(new XYFunctionPlotItem(pa, ps));
                }
                else
                {
                    XYFunctionPlotItem s = (XYFunctionPlotItem)o;
                    s.Data  = pa;
                    s.Style = ps;
                    return(s);
                }
            }
Exemple #6
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                XYFunctionPlotData     pa   = (XYFunctionPlotData)info.GetValue("Data", typeof(XYColumnPlotData));
                XYLineScatterPlotStyle lsps = (XYLineScatterPlotStyle)info.GetValue("Style", typeof(XYLineScatterPlotStyle));

                G2DPlotStyleCollection ps = new G2DPlotStyleCollection();

                ps.Add(new ScatterPlotStyle(lsps.ScatterStyle));
                ps.Add(new LinePlotStyle(lsps.XYPlotLineStyle));

                if (null == o)
                {
                    return(new XYFunctionPlotItem(pa, ps));
                }
                else
                {
                    XYFunctionPlotItem s = (XYFunctionPlotItem)o;
                    s.Data  = pa;
                    s.Style = ps;
                    return(s);
                }
            }
    public override void Run(Altaxo.Graph.GUI.GraphController ctrl)
    {
      FunctionEvaluationScript script = null; // 

      if(script==null)
        script = new FunctionEvaluationScript();

      object[] args = new object[]{script,new ScriptExecutionHandler(this.EhScriptExecution)};
      if(Current.Gui.ShowDialog(args, "Function script"))
      {
        ctrl.EnsureValidityOfCurrentLayerNumber();

        script = (FunctionEvaluationScript)args[0];
        XYFunctionPlotItem functItem = new XYFunctionPlotItem(new XYFunctionPlotData(script),new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line));
        ctrl.Doc.Layers[ctrl.CurrentLayerNumber].PlotItems.Add(functItem);
      }
    }
    public void OnAfterFittingStep()
    {


      if (_view != null)
        _view.SetChiSquare(this._chiSquare);



      if (_doc.FitContext is Altaxo.Graph.GUI.GraphController)
      {
        // for every dependent variable in the FitEnsemble, create a function graph
        Altaxo.Graph.GUI.GraphController graph = _doc.FitContext as Altaxo.Graph.GUI.GraphController;

        int funcNumber = 0;
        for (int i = 0; i < _doc.FitEnsemble.Count; i++)
        {
          FitElement fitEle = _doc.FitEnsemble[i];

          for (int k = 0; k < fitEle.NumberOfDependentVariables; k++, funcNumber++)
          {
            if (funcNumber < _functionPlotItems.Count && _functionPlotItems[funcNumber] != null)
            {
              XYFunctionPlotItem plotItem = (XYFunctionPlotItem)_functionPlotItems[funcNumber];
              FitFunctionToScalarFunctionDDWrapper wrapper = (FitFunctionToScalarFunctionDDWrapper)plotItem.Data.Function;
              wrapper.Initialize(fitEle.FitFunction, k, 0, _doc.GetParametersForFitElement(i));
            }
            else
            {
              FitFunctionToScalarFunctionDDWrapper wrapper = new FitFunctionToScalarFunctionDDWrapper(fitEle.FitFunction, k, _doc.GetParametersForFitElement(i));
              XYFunctionPlotData plotdata = new XYFunctionPlotData(wrapper);
              XYFunctionPlotItem plotItem = new XYFunctionPlotItem(plotdata, new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line));
              graph.ActiveLayer.PlotItems.Add(plotItem);
              _functionPlotItems.Add(plotItem);
            }
          }
        }

        // if there are more elements in _functionPlotItems, remove them from the graph
        for (int i = _functionPlotItems.Count - 1; i >= funcNumber; --i)
        {
          if (_functionPlotItems[i] != null)
          {
            graph.ActiveLayer.PlotItems.Remove((IGPlotItem)_functionPlotItems[i]);
            _functionPlotItems.RemoveAt(i);

          }
        }
        graph.RefreshGraph();
      }
    }
Exemple #9
0
		public XYFunctionPlotItem(XYFunctionPlotItem from)
		{
			CopyFrom((PlotItem)from);
		}
Exemple #10
0
		public override void Run(GraphController ctrl)
		{
			HostLayer activeLayer;
			ctrl.Doc.RootLayer.IsValidIndex(ctrl.CurrentLayerNumber, out activeLayer);

			if (!(activeLayer is XYPlotLayer))
				return;

			FunctionEvaluationScript script = null; //

			if (script == null)
				script = new FunctionEvaluationScript();

			object[] args = new object[] { script, new ScriptExecutionHandler(this.EhScriptExecution) };
			if (Current.Gui.ShowDialog(args, "Function script"))
			{
				ctrl.EnsureValidityOfCurrentLayerNumber();

				script = (FunctionEvaluationScript)args[0];
				XYFunctionPlotItem functItem = new XYFunctionPlotItem(new XYFunctionPlotData(script), new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line, activeLayer.GetPropertyContext()));
				((XYPlotLayer)activeLayer).PlotItems.Add(functItem);
			}
		}
Exemple #11
0
 public XYFunctionPlotItem(XYFunctionPlotItem from)
 {
     CopyFrom((PlotItem)from);
 }
Exemple #12
0
		public static string Fit(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl, int order, double fitCurveXmin, double fitCurveXmax, bool showFormulaOnGraph)
		{
			string error;

			double[] xarr, yarr;
			error = GetActivePlotPoints(ctrl, out xarr, out yarr);
			int numberOfDataPoints = xarr.Length;

			if (null != error)
				return error;

			string[] plotNames = GetActivePlotName(ctrl);

			int numberOfParameter = order + 1;
			double[] parameter = new double[numberOfParameter];
			LinearFitBySvd fit =
				new LinearFitBySvd(
				xarr, yarr, null, numberOfDataPoints, order + 1, new FunctionBaseEvaluator(EvaluatePolynomialBase), 1E-5);

			// Output of results

			Current.Console.WriteLine("");
			Current.Console.WriteLine("---- " + DateTime.Now.ToString() + " -----------------------");
			Current.Console.WriteLine("Polynomial regression of order {0} of {1} over {2}", order, plotNames[1], plotNames[0]);

			Current.Console.WriteLine(
				"Name           Value               Error               F-Value             Prob>F");

			for (int i = 0; i < fit.Parameter.Length; i++)
				Current.Console.WriteLine("A{0,-3} {1,20} {2,20} {3,20} {4,20}",
					i,
					fit.Parameter[i],
					fit.StandardErrorOfParameter(i),
					fit.TofParameter(i),
					1 - FDistribution.CDF(fit.TofParameter(i), numberOfParameter, numberOfDataPoints - 1)
					);

			Current.Console.WriteLine("R²: {0}, Adjusted R²: {1}",
				fit.RSquared,
				fit.AdjustedRSquared);

			Current.Console.WriteLine("------------------------------------------------------------");
			Current.Console.WriteLine("Source of  Degrees of");
			Current.Console.WriteLine("variation  freedom          Sum of Squares          Mean Square          F0                   P value");

			double regressionmeansquare = fit.RegressionCorrectedSumOfSquares / numberOfParameter;
			double residualmeansquare = fit.ResidualSumOfSquares / (numberOfDataPoints - numberOfParameter - 1);

			Current.Console.WriteLine("Regression {0,10} {1,20} {2,20} {3,20} {4,20}",
				numberOfParameter,
				fit.RegressionCorrectedSumOfSquares,
				fit.RegressionCorrectedSumOfSquares / numberOfParameter,
				regressionmeansquare / residualmeansquare,
				1 - FDistribution.CDF(regressionmeansquare / residualmeansquare, numberOfParameter, numberOfDataPoints - 1)
				);

			Current.Console.WriteLine("Residual   {0,10} {1,20} {2,20}",
				numberOfDataPoints - 1 - numberOfParameter,
				fit.ResidualSumOfSquares,
				residualmeansquare
				);

			Current.Console.WriteLine("Total      {0,10} {1,20}",
				numberOfDataPoints - 1,
				fit.TotalCorrectedSumOfSquares

				);

			Current.Console.WriteLine("------------------------------------------------------------");

			// add the fit curve to the graph
			IScalarFunctionDD plotfunction = new PolynomialFunction(fit.Parameter);
			XYFunctionPlotItem fittedCurve = new XYFunctionPlotItem(new XYFunctionPlotData(plotfunction), new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line, ctrl.Doc.GetPropertyContext()));

			var xylayer = ctrl.ActiveLayer as XYPlotLayer;
			if (null != xylayer)
				xylayer.PlotItems.Add(fittedCurve);

			return null;
		}