LibreOffice Module chart2 (master) 1
MeanValueRegressionCurveCalculator.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21
22#include <osl/diagnose.h>
23
24#include <cmath>
25#include <limits>
26
27using namespace ::com::sun::star;
28
29namespace chart
30{
31
33 m_fMeanValue( std::numeric_limits<double>::quiet_NaN() )
34{
35}
36
38{}
39
40// ____ XRegressionCurveCalculator ____
42 const uno::Sequence< double >& /*aXValues*/,
43 const uno::Sequence< double >& aYValues )
44{
45 const sal_Int32 nDataLength = aYValues.getLength();
46 sal_Int32 nMax = nDataLength;
47 double fSumY = 0.0;
48 const double * pY = aYValues.getConstArray();
49
50 for( sal_Int32 i = 0; i < nDataLength; ++i )
51 {
52 if( std::isnan( pY[i] ) ||
53 std::isinf( pY[i] ))
54 --nMax;
55 else
56 fSumY += pY[i];
57 }
58
60
61 if( nMax == 0 )
62 {
63 m_fMeanValue = std::numeric_limits<double>::quiet_NaN();
64 }
65 else
66 {
67 m_fMeanValue = fSumY / static_cast< double >( nMax );
68
69 // correlation coefficient: standard deviation
70 if( nMax > 1 )
71 {
72 double fErrorSum = 0.0;
73 for( sal_Int32 i = 0; i < nDataLength; ++i )
74 {
75 if( !std::isnan( pY[i] ) &&
76 !std::isinf( pY[i] ))
77 {
78 double v = m_fMeanValue - pY[i];
79 fErrorSum += (v*v);
80 }
81 }
82 OSL_ASSERT( fErrorSum >= 0.0 );
83 m_fCorrelationCoefficient = sqrt( fErrorSum / (nMax - 1 ));
84 }
85 }
86}
87
89{
90 return m_fMeanValue;
91}
92
94 double min, double max, ::sal_Int32 nPointCount,
97 sal_Bool bMaySkipPointsInCalculation )
98{
99 if( bMaySkipPointsInCalculation )
100 {
101 // optimize result
103 { max, m_fMeanValue } };
104
105 return aResult;
106 }
107 return RegressionCurveCalculator::getCurveValues( min, max, nPointCount, xScalingX, xScalingY, bMaySkipPointsInCalculation );
108}
109
111 const uno::Reference< util::XNumberFormatter >& xNumFormatter,
112 sal_Int32 nNumberFormatKey, sal_Int32* pFormulaLength /* = nullptr */ ) const
113{
114 OUString aBuf(mYName + " = ");
115 if ( pFormulaLength )
116 {
117 *pFormulaLength -= aBuf.getLength();
118 if ( *pFormulaLength <= 0 )
119 return "###";
120 }
121 return ( aBuf + getFormattedString( xNumFormatter, nNumberFormatKey, m_fMeanValue, pFormulaLength ) );
122}
123
124} // namespace chart
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual double SAL_CALL getCurveValue(double x) override
virtual OUString ImplGetRepresentation(const css::uno::Reference< css::util::XNumberFormatter > &xNumFormatter, sal_Int32 nNumberFormatKey, sal_Int32 *pFormulaLength=nullptr) const override
virtual void SAL_CALL recalculateRegression(const css::uno::Sequence< double > &aXValues, const css::uno::Sequence< double > &aYValues) override
virtual css::uno::Sequence< css::geometry::RealPoint2D > SAL_CALL getCurveValues(double min, double max, sal_Int32 nPointCount, const css::uno::Reference< css::chart2::XScaling > &xScalingX, const css::uno::Reference< css::chart2::XScaling > &xScalingY, sal_Bool bMaySkipPointsInCalculation) override
static OUString getFormattedString(const css::uno::Reference< css::util::XNumberFormatter > &xNumFormatter, sal_Int32 nNumberFormatKey, double fNumber, const sal_Int32 *pStringLength)
virtual css::uno::Sequence< css::geometry::RealPoint2D > SAL_CALL getCurveValues(double min, double max, sal_Int32 nPointCount, const css::uno::Reference< css::chart2::XScaling > &xScalingX, const css::uno::Reference< css::chart2::XScaling > &xScalingY, sal_Bool bMaySkipPointsInCalculation) override
float v
#define max(a, b)
aBuf
int i
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
unsigned char sal_Bool