-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6705f01
commit 4de1767
Showing
10 changed files
with
366 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<!-- | ||
Copyright (c) 2019-2026, Hossein Moein | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of Hossein Moein and/or the DataFrame nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<style> | ||
body { | ||
background-image: linear-gradient(Azure, AliceBlue, GhostWhite, WhiteSmoke); | ||
} | ||
|
||
a { color: #FF5555; } | ||
</style> | ||
</head> | ||
|
||
<body style="font-family: Georgia, serif"> | ||
<font size="+3">←</font> <a href="https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/DataFrame.html">Back to Documentations</a><BR><BR> | ||
|
||
<table border="1"> | ||
|
||
<tr bgcolor="lightblue"> | ||
<th>Signature</th> <th>Description</th> | ||
</tr> | ||
|
||
<tr bgcolor="Azure"> | ||
<td bgcolor="blue"> <font color="white"> | ||
<PRE><B> | ||
template<typename T> | ||
struct CanonCorrResult { | ||
|
||
// These values represent the strength of the linear relationship between | ||
// each pair of canonical variates, ranging from -1 to 1, with higher | ||
// absolute values signifying a stronger association. | ||
// | ||
std::vector<T> coeffs { }; // Canonical correlation coefficients | ||
|
||
// The Redundancy Index is a measure that indicates how much variance in | ||
// one set of variables is explained by the linear combination of the other | ||
// set of variables. This was proposed by Stewart and Love (1968). | ||
// | ||
T x_red_idx { }; // Redundancy index for X | ||
T y_red_idx { }; // Redundancy index for Y | ||
}; | ||
</font> | ||
</B></PRE> | ||
</td> | ||
<td> | ||
Result of Canonical Correlation Analysis as returned by canon_corr() interface<BR> | ||
</td> | ||
</tr> | ||
|
||
</table> | ||
|
||
<BR> | ||
<table border="1"> | ||
|
||
<tr bgcolor="lightblue"> | ||
<th>Signature</th> <th>Description</th> <th>Parameters</th> | ||
</tr> | ||
|
||
<tr bgcolor="Azure"> | ||
<td bgcolor="blue"> <font color="white"> | ||
<PRE><B> | ||
template<typename T> | ||
CanonCorrResult<T> | ||
canon_corr(std::vector<const char *> &&X_col_names, | ||
std::vector<const char *> &&Y_col_names) const; | ||
</B></PRE></font> | ||
</td> | ||
<td> | ||
This performs Canonical Correlation Analysis (CCA) between two sets of columns <I>X</I> and <I>Y</I>. It returns the result in a struct defined above.<BR> | ||
CCA is a statistical method for examining and measuring correlations between two sets of variables. Fundamentally, CCA looks for linear combinations of variables, also referred to as canonical variables, within each set so that the correlation between them is maximized. Finding relationships and patterns of linkage between the two groups is the main objective.<BR><BR> | ||
|
||
<B>NOTE</B>: Number of columns in each set must be the same<BR> | ||
</td> | ||
<td width="28%"> | ||
<B>T</B>: Type of the named columns<BR> | ||
<B>X_col_names</B>: Names of the first set of columns<BR> | ||
<B>Y_col_names</B>: Names of the second set of columns<BR> | ||
</td> | ||
</tr> | ||
|
||
</table> | ||
|
||
<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">static</span> <span style="color:#800000; font-weight:bold; ">void</span> test_canon_corr<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span> <span style="color:#800080; ">{</span></span> | ||
<span class="line_wrapper"></span> | ||
<span class="line_wrapper"> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">cout</span> <span style="color:#808030; "><</span><span style="color:#808030; "><</span> <span style="color:#800000; ">"</span><span style="color:#0f69ff; ">\n</span><span style="color:#0000e6; ">Testing canon_corr( ) ...</span><span style="color:#800000; ">"</span> <span style="color:#808030; "><</span><span style="color:#808030; "><</span> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">endl</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"></span> | ||
<span class="line_wrapper"> StrDataFrame df<span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"></span> | ||
<span class="line_wrapper"> <span style="color:#800000; font-weight:bold; ">try</span> <span style="color:#800080; ">{</span></span> | ||
<span class="line_wrapper"> df<span style="color:#808030; ">.</span><span style="color:#603000; ">read</span><span style="color:#808030; ">(</span><span style="color:#800000; ">"</span><span style="color:#0000e6; ">IBM.csv</span><span style="color:#800000; ">"</span><span style="color:#808030; ">,</span> io_format<span style="color:#800080; ">::</span>csv2<span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"> <span style="color:#800080; ">}</span></span> | ||
<span class="line_wrapper"> <span style="color:#800000; font-weight:bold; ">catch</span> <span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">const</span> DataFrameError <span style="color:#808030; ">&</span>ex<span style="color:#808030; ">)</span> <span style="color:#800080; ">{</span></span> | ||
<span class="line_wrapper"> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">cout</span> <span style="color:#808030; "><</span><span style="color:#808030; "><</span> ex<span style="color:#808030; ">.</span>what<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span> <span style="color:#808030; "><</span><span style="color:#808030; "><</span> <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">endl</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"> <span style="color:#800080; ">}</span></span> | ||
<span class="line_wrapper"></span> | ||
<span class="line_wrapper"> <span style="color:#800000; font-weight:bold; ">const</span> <span style="color:#800000; font-weight:bold; ">auto</span> result <span style="color:#808030; ">=</span> df<span style="color:#808030; ">.</span>canon_corr<span style="color:#800080; "><</span><span style="color:#800000; font-weight:bold; ">double</span><span style="color:#800080; ">></span><span style="color:#808030; ">(</span><span style="color:#800080; ">{</span> <span style="color:#800000; ">"</span><span style="color:#0000e6; ">IBM_Close</span><span style="color:#800000; ">"</span><span style="color:#808030; ">,</span> <span style="color:#800000; ">"</span><span style="color:#0000e6; ">IBM_Open</span><span style="color:#800000; ">"</span> <span style="color:#800080; ">}</span><span style="color:#808030; ">,</span> <span style="color:#800080; ">{</span> <span style="color:#800000; ">"</span><span style="color:#0000e6; ">IBM_High</span><span style="color:#800000; ">"</span><span style="color:#808030; ">,</span> <span style="color:#800000; ">"</span><span style="color:#0000e6; ">IBM_Low</span><span style="color:#800000; ">"</span> <span style="color:#800080; ">}</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"></span> | ||
<span class="line_wrapper"> assert<span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>coeffs<span style="color:#808030; ">.</span>size<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span> <span style="color:#808030; ">=</span><span style="color:#808030; ">=</span> <span style="color:#008c00; ">2</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"> assert<span style="color:#808030; ">(</span><span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">fabs</span><span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>coeffs<span style="color:#808030; ">[</span><span style="color:#008c00; ">0</span><span style="color:#808030; ">]</span> <span style="color:#808030; ">-</span> <span style="color:#008000; ">0.999944</span><span style="color:#808030; ">)</span> <span style="color:#808030; "><</span> <span style="color:#008000; ">0.000001</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"> assert<span style="color:#808030; ">(</span><span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">fabs</span><span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>coeffs<span style="color:#808030; ">[</span><span style="color:#008c00; ">1</span><span style="color:#808030; ">]</span> <span style="color:#808030; ">-</span> <span style="color:#008000; ">0.262927</span><span style="color:#808030; ">)</span> <span style="color:#808030; "><</span> <span style="color:#008000; ">0.000001</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"> assert<span style="color:#808030; ">(</span><span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">fabs</span><span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>x_red_idx <span style="color:#808030; ">-</span> <span style="color:#008000; ">0.534073</span><span style="color:#808030; ">)</span> <span style="color:#808030; "><</span> <span style="color:#008000; ">0.000001</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"> assert<span style="color:#808030; ">(</span><span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">fabs</span><span style="color:#808030; ">(</span>result<span style="color:#808030; ">.</span>y_red_idx <span style="color:#808030; ">-</span> <span style="color:#008000; ">0.535897</span><span style="color:#808030; ">)</span> <span style="color:#808030; "><</span> <span style="color:#008000; ">0.000001</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span></span> | ||
<span class="line_wrapper"><span style="color:#800080; ">}</span></span> | ||
<span class="line_wrapper"></span></pre> | ||
|
||
<BR><img src="https://github.com/hosseinmoein/DataFrame/blob/master/docs/LionLookingUp.jpg?raw=true" alt="C++ DataFrame" | ||
width="200" height="200" style="float:right"/> | ||
|
||
</body> | ||
</html> | ||
|
||
<!-- | ||
Local Variables: | ||
mode:HTML | ||
tab-width:4 | ||
c-basic-offset:4 | ||
End: | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.