File: outSDo.cpp

package info (click to toggle)
r-cran-pcapp 1.9-73-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 800 kB
  • sloc: cpp: 5,961; ansic: 917; sh: 13; makefile: 2
file content (126 lines) | stat: -rw-r--r-- 2,630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "outSDo.h"
#include "L1Median.h"

	double ApplyCenterMethod (const SCVecD &v, t_size dwMethod)
	{
		switch (dwMethod)
		{
		case 0:
			return 0 ;
		case 1:
			return mean (v) ;
		case 2:
			return median (v) ;
		}

		ASSERT (0) ;
		return 0 ;
	}

#define IM_OBS		0
#define IM_DIFFOBS	1
#define IM_RANDOM	2
#define IM_RANDDIFFOBS 3

	CSDoOut::CSDoOut (int *pnParIn, double *pdX, double *pdMaxMaha, int *pnNChanged)
		: m_dwN (pnParIn[0]), m_dwP (pnParIn[1]), m_dwIterMethod (pnParIn[2]), m_dwIterParam (pnParIn[3]), m_dwCenterMethod (pnParIn[4]), m_dwScatterMethod (pnParIn[5]), m_dwReset (pnParIn[6])
		, m_mX (pdX, m_dwN, m_dwP)
		, m_vMaxMaha (pdMaxMaha, m_dwN)
		, m_dwNDir ((m_dwIterMethod == IM_OBS) ? m_dwN : m_dwIterParam)	//	number of checked directions
		, m_vXProj (m_dwN), m_vCurDir (m_dwP)
		, m_pnNChanged (pnNChanged), m_pdDiff (pdX)
		, m_pdXProj (m_vXProj), m_pdEndXProj (m_vXProj.GetDataEnd ()), m_pdMaxMaha (m_vMaxMaha)
	{
	}

	void CSDoOut::Calc ()
	{
		if (m_dwReset)
			m_vMaxMaha.Reset (0) ;

		switch (m_dwIterMethod)
		{
		case IM_OBS :
			IterObs () ;
			break ;
		case IM_DIFFOBS :
			IterDiffObs (m_dwNDir) ;
			break ;
		case IM_RANDOM :
			IterRand (m_dwNDir) ;
			break ;
		case IM_RANDDIFFOBS :
			IterRandDiffObs (m_dwNDir) ;
			break ;
		}
	}

	void CSDoOut::IterObs ()
	{
		t_size i ;
		double dNorm ;
		int nChanged ;
//		for (i = m_dwN - 1; i != NAI; i)	//	can't be used because of m_vChanged
		for (i = 0; i < m_dwN; ++i)
		{
			CopyRow (*m_vCurDir, m_mX, i) ;

			EO<SOP::Apa_sqr_B>::SVc (dNorm = 0, m_vCurDir) ;
			EO<SOP::a_divide>::VSc (*m_vCurDir, sqrt (dNorm)) ;

			nChanged = DoDir (m_vCurDir) ;
			if (m_pnNChanged)
				m_pnNChanged[i] = nChanged ;
//			if (m_bSaveChanged)
//				m_vChanged(i) = nChanged ;
		}
	}

	void CSDoOut::IterDiffObs (int n)
	{
		
	}

	void CSDoOut::IterRandDiffObs (int n)
	{
		
	}

	void CSDoOut::IterRand (int n)
	{
		
	}

	int CSDoOut::DoDir (const SCVecD &vLoad)
	{
		m_vXProj.Reset (0) ;
		EO<SOP::ApaBmC>::VMcVct (*m_vXProj, m_mX, vLoad) ;

		const double dCenter = ApplyCenterMethod (m_vXProj, m_dwCenterMethod) ;
		const double dScatter = ApplyMethod (m_vXProj, m_dwScatterMethod) ;

		double *pProj = m_pdXProj, *pdMaxMaha = m_pdMaxMaha ;

		int nChanged = 0 ;

		double dDiff = 0, dCurMaha ;

		while (pProj < m_pdEndXProj)
		{
			//nChanged += sm_setmax_b  (*pdMaxMaha, (*pProj - dCenter) / dScatter) ;

			dCurMaha = fabs(*pProj - dCenter) / dScatter ;

			if (dCurMaha > *pdMaxMaha)
			{
				*pdMaxMaha = dCurMaha ;
				++nChanged ;
				dDiff += dCurMaha - *pdMaxMaha ;
			}

			++ pProj ;
			++ pdMaxMaha ;
		}

		return nChanged ;
	}