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
140b4f7c
Commit
140b4f7c
authored
Apr 29, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made neutralize workable with groups
parent
5e4c6ca9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
neutralize.py
alphamind/data/neutralize.py
+24
-3
No files found.
alphamind/data/neutralize.py
View file @
140b4f7c
...
@@ -7,9 +7,21 @@ Created on 2017-4-25
...
@@ -7,9 +7,21 @@ Created on 2017-4-25
import
numpy
as
np
import
numpy
as
np
from
numpy.linalg
import
solve
from
numpy.linalg
import
solve
from
alphamind.aggregate
import
groupby
def
neutralize
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
np
.
ndarray
:
def
neutralize
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
,
groups
:
np
.
ndarray
=
None
)
->
np
.
ndarray
:
if
groups
is
not
None
:
res
=
np
.
zeros
(
y
.
shape
)
groups_ids
=
groupby
(
groups
)
for
curr_idx
in
groups_ids
:
curr_x
=
x
[
curr_idx
]
curr_y
=
y
[
curr_idx
]
b
=
ls_fit
(
x
[
curr_idx
],
y
[
curr_idx
])
res
[
curr_idx
]
=
ls_res
(
curr_x
,
curr_y
,
b
)
return
res
else
:
b
=
ls_fit
(
x
,
y
)
b
=
ls_fit
(
x
,
y
)
return
ls_res
(
x
,
y
,
b
)
return
ls_res
(
x
,
y
,
b
)
...
@@ -22,3 +34,12 @@ def ls_fit(x: np.ndarray, y: np.ndarray) -> np.ndarray:
...
@@ -22,3 +34,12 @@ def ls_fit(x: np.ndarray, y: np.ndarray) -> np.ndarray:
def
ls_res
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
,
b
:
np
.
ndarray
)
->
np
.
ndarray
:
def
ls_res
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
,
b
:
np
.
ndarray
)
->
np
.
ndarray
:
return
y
-
x
@
b
return
y
-
x
@
b
if
__name__
==
'__main__'
:
x
=
np
.
random
.
randn
(
3000
,
3
)
y
=
np
.
random
.
randn
(
3000
,
2
)
groups
=
np
.
random
.
randint
(
30
,
size
=
3000
)
print
(
neutralize
(
x
,
y
,
groups
))
\ No newline at end of file
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