1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "MeanValueRegressionCurveCalculator.hxx"
32 #include <rtl/math.hxx>
33 #include <rtl/ustrbuf.hxx>
35 using namespace ::com::sun::star
;
37 using ::rtl::OUString
;
38 using ::rtl::OUStringBuffer
;
43 MeanValueRegressionCurveCalculator::MeanValueRegressionCurveCalculator() :
46 ::rtl::math::setNan( & m_fMeanValue
);
49 MeanValueRegressionCurveCalculator::~MeanValueRegressionCurveCalculator()
52 // ____ XRegressionCurveCalculator ____
53 void SAL_CALL
MeanValueRegressionCurveCalculator::recalculateRegression(
54 const uno::Sequence
< double >& /*aXValues*/,
55 const uno::Sequence
< double >& aYValues
)
56 throw (uno::RuntimeException
)
58 const sal_Int32 nDataLength
= aYValues
.getLength();
59 sal_Int32 nMax
= nDataLength
;
61 const double * pY
= aYValues
.getConstArray();
63 for( sal_Int32 i
= 0; i
< nDataLength
; ++i
)
65 if( ::rtl::math::isNan( pY
[i
] ) ||
66 ::rtl::math::isInf( pY
[i
] ))
72 m_fCorrelationCoeffitient
= 0.0;
76 ::rtl::math::setNan( & m_fMeanValue
);
80 m_fMeanValue
= fSumY
/ static_cast< double >( nMax
);
82 // correlation coefficient: standard deviation
85 double fErrorSum
= 0.0;
86 for( sal_Int32 i
= 0; i
< nDataLength
; ++i
)
88 if( !::rtl::math::isNan( pY
[i
] ) &&
89 !::rtl::math::isInf( pY
[i
] ))
91 double v
= m_fMeanValue
- pY
[i
];
95 OSL_ASSERT( fErrorSum
>= 0.0 );
96 m_fCorrelationCoeffitient
= sqrt( fErrorSum
/ (nMax
- 1 ));
101 double SAL_CALL
MeanValueRegressionCurveCalculator::getCurveValue( double /*x*/ )
102 throw (lang::IllegalArgumentException
,
103 uno::RuntimeException
)
109 uno::Sequence
< geometry::RealPoint2D
> SAL_CALL
MeanValueRegressionCurveCalculator::getCurveValues(
110 double min
, double max
, ::sal_Int32 nPointCount
,
111 const uno::Reference
< chart2::XScaling
>& xScalingX
,
112 const uno::Reference
< chart2::XScaling
>& xScalingY
,
113 ::sal_Bool bMaySkipPointsInCalculation
)
114 throw (lang::IllegalArgumentException
,
115 uno::RuntimeException
)
117 if( bMaySkipPointsInCalculation
)
120 uno::Sequence
< geometry::RealPoint2D
> aResult( 2 );
122 aResult
[0].Y
= m_fMeanValue
;
124 aResult
[1].Y
= m_fMeanValue
;
128 return RegressionCurveCalculator::getCurveValues( min
, max
, nPointCount
, xScalingX
, xScalingY
, bMaySkipPointsInCalculation
);
131 OUString
MeanValueRegressionCurveCalculator::ImplGetRepresentation(
132 const uno::Reference
< util::XNumberFormatter
>& xNumFormatter
,
133 ::sal_Int32 nNumberFormatKey
) const
135 OUStringBuffer
aBuf( C2U( "f(x) = " ));
137 aBuf
.append( getFormattedString( xNumFormatter
, nNumberFormatKey
, m_fMeanValue
));
139 return aBuf
.makeStringAndClear();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */