Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
e86d6f8f
Commit
e86d6f8f
authored
May 01, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed a issue for array ordering
parent
5df30c1b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
7 deletions
+22
-7
aggregate.pyx
alphamind/aggregate.pyx
+4
-1
neutralize.py
alphamind/data/neutralize.py
+3
-4
standardize.py
alphamind/data/standardize.py
+13
-1
winsorize.py
alphamind/data/winsorize.py
+2
-1
No files found.
alphamind/aggregate.pyx
View file @
e86d6f8f
...
@@ -13,7 +13,6 @@ from libc.math cimport sqrt
...
@@ -13,7 +13,6 @@ from libc.math cimport sqrt
from libc.math cimport fabs
from libc.math cimport fabs
from libc.stdlib cimport malloc
from libc.stdlib cimport malloc
from libc.stdlib cimport free
from libc.stdlib cimport free
from numpy import array
from libcpp.vector cimport vector as cpp_vector
from libcpp.vector cimport vector as cpp_vector
from libcpp.unordered_map cimport unordered_map as cpp_map
from libcpp.unordered_map cimport unordered_map as cpp_map
from cython.operator cimport dereference as deref
from cython.operator cimport dereference as deref
...
@@ -220,6 +219,8 @@ cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str f
...
@@ -220,6 +219,8 @@ cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str f
cdef size_t loop_idx1
cdef size_t loop_idx1
cdef size_t loop_idx2
cdef size_t loop_idx2
x = np.ascontiguousarray(x)
try:
try:
if func == 'mean':
if func == 'mean':
value_data_ptr = agg_mean(mapped_groups, max_g[0], &x[0, 0], length, width)
value_data_ptr = agg_mean(mapped_groups, max_g[0], &x[0, 0], length, width)
...
@@ -258,6 +259,8 @@ cpdef np.ndarray[double, ndim=2] aggregate(long[:] groups, double[:, :] x, str f
...
@@ -258,6 +259,8 @@ cpdef np.ndarray[double, ndim=2] aggregate(long[:] groups, double[:, :] x, str f
cdef double* value_data_ptr
cdef double* value_data_ptr
cdef np.ndarray[double, ndim=2] res
cdef np.ndarray[double, ndim=2] res
x = np.ascontiguousarray(x)
try:
try:
if func == 'mean':
if func == 'mean':
value_data_ptr = agg_mean(mapped_groups, max_g[0], &x[0, 0], length, width)
value_data_ptr = agg_mean(mapped_groups, max_g[0], &x[0, 0], length, width)
...
...
alphamind/data/neutralize.py
View file @
e86d6f8f
...
@@ -50,13 +50,13 @@ def neutralize(x: np.ndarray, y: np.ndarray, groups: np.ndarray=None, output_exp
...
@@ -50,13 +50,13 @@ def neutralize(x: np.ndarray, y: np.ndarray, groups: np.ndarray=None, output_exp
if
output_explained
:
if
output_explained
:
explained
=
ls_explain
(
x
,
b
)
explained
=
ls_explain
(
x
,
b
)
el
if
output_exposure
:
if
output_exposure
:
exposure
=
b
exposure
=
b
output_dict
=
{}
output_dict
=
{}
if
output_explained
:
if
output_explained
:
output_dict
[
'explained'
]
=
explained
output_dict
[
'explained'
]
=
explained
el
if
output_exposure
:
if
output_exposure
:
output_dict
[
'exposure'
]
=
exposure
output_dict
[
'exposure'
]
=
exposure
if
output_dict
:
if
output_dict
:
...
@@ -95,5 +95,4 @@ if __name__ == '__main__':
...
@@ -95,5 +95,4 @@ if __name__ == '__main__':
y
=
np
.
random
.
randn
(
3000
,
2
)
y
=
np
.
random
.
randn
(
3000
,
2
)
groups
=
np
.
random
.
randint
(
30
,
size
=
3000
)
groups
=
np
.
random
.
randint
(
30
,
size
=
3000
)
b
=
ls_fit
(
x
,
y
)
print
(
neutralize
(
x
,
y
,
groups
,
output_explained
=
True
,
output_exposure
=
True
))
ls_explained
(
x
,
y
,
b
)
\ No newline at end of file
alphamind/data/standardize.py
View file @
e86d6f8f
...
@@ -6,12 +6,14 @@ Created on 2017-4-25
...
@@ -6,12 +6,14 @@ Created on 2017-4-25
"""
"""
import
numpy
as
np
import
numpy
as
np
from
numpy
import
ascontiguousarray
from
alphamind.aggregate
import
transform
from
alphamind.aggregate
import
transform
def
standardize
(
x
:
np
.
ndarray
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
def
standardize
(
x
:
np
.
ndarray
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
x
=
ascontiguousarray
(
x
)
if
groups
is
not
None
:
if
groups
is
not
None
:
mean_values
=
transform
(
groups
,
x
,
'mean'
)
mean_values
=
transform
(
groups
,
x
,
'mean'
)
std_values
=
transform
(
groups
,
x
,
'std'
)
std_values
=
transform
(
groups
,
x
,
'std'
)
...
@@ -19,3 +21,13 @@ def standardize(x: np.ndarray, groups: np.ndarray=None) -> np.ndarray:
...
@@ -19,3 +21,13 @@ def standardize(x: np.ndarray, groups: np.ndarray=None) -> np.ndarray:
return
(
x
-
mean_values
)
/
std_values
return
(
x
-
mean_values
)
/
std_values
else
:
else
:
return
(
x
-
x
.
mean
(
axis
=
0
))
/
x
.
std
(
axis
=
0
)
return
(
x
-
x
.
mean
(
axis
=
0
))
/
x
.
std
(
axis
=
0
)
if
__name__
==
'__main__'
:
import
pandas
as
pd
df
=
pd
.
read_csv
(
'd:/test_data.csv'
,
index_col
=
0
)
x
=
df
.
values
groups
=
df
.
index
.
values
.
astype
(
int
)
standardize
(
x
,
groups
)
alphamind/data/winsorize.py
View file @
e86d6f8f
...
@@ -6,11 +6,12 @@ Created on 2017-4-25
...
@@ -6,11 +6,12 @@ Created on 2017-4-25
"""
"""
import
numpy
as
np
import
numpy
as
np
from
numpy
import
ascontiguousarray
from
alphamind.aggregate
import
transform
from
alphamind.aggregate
import
transform
def
winsorize_normal
(
x
:
np
.
ndarray
,
num_stds
:
int
=
3
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
def
winsorize_normal
(
x
:
np
.
ndarray
,
num_stds
:
int
=
3
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
x
=
ascontiguousarray
(
x
)
if
groups
is
not
None
:
if
groups
is
not
None
:
mean_values
=
transform
(
groups
,
x
,
'mean'
)
mean_values
=
transform
(
groups
,
x
,
'mean'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment