Skip to content

Commit 2cd72d1

Browse files
authored
Merge pull request #383 from oooo26/master
Update pypi workflow & improve codecov
2 parents 31198ec + 516111d commit 2cd72d1

7 files changed

Lines changed: 167 additions & 52 deletions

File tree

.github/workflows/pypi.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ jobs:
3131
- name: Check metadata
3232
run: |
3333
pipx run twine check dist/*
34+
realpath dist/*
3435
35-
- uses: actions/upload-artifact@v2
36+
- uses: actions/upload-artifact@v3
3637
with:
37-
path: dist/*.tar.gz
38+
path: python/dist/*
3839

3940
build_wheels:
4041
name: Wheels on ${{ matrix.os }}

python/abess/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# @Site :
66
# @File : __init__.py
77

8-
__version__ = "0.4.2"
8+
__version__ = "0.4.3"
99
__author__ = ("Jin Zhu, Kangkang Jiang, "
1010
"Junhao Huang, Yanhang Zhang, "
1111
"Yanhang Zhang, Shiyun Lin, "

python/abess/decomposition.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ def ratio(self, X):
110110
"""
111111
X = new_data_check(self, X)
112112
s = np.cov(X.T)
113-
if len(self.coef_.shape) == 1:
114-
explain = self.coef_.T.dot(s).dot(self.coef_)
115-
else:
116-
explain = np.sum(np.diag(self.coef_.T.dot(s).dot(self.coef_)))
117-
if isinstance(s, (int, float)):
118-
full = s
119-
else:
120-
full = np.sum(np.diag(s))
113+
# if len(self.coef_.shape) == 1:
114+
# explain = self.coef_.T.dot(s).dot(self.coef_)
115+
# else:
116+
explain = np.sum(np.diag(self.coef_.T.dot(s).dot(self.coef_)))
117+
# if isinstance(s, (int, float)):
118+
# full = s
119+
# else:
120+
full = np.sum(np.diag(s))
121121
return explain / full
122122

123123
def fit(self, X=None, is_normal=False,
@@ -261,7 +261,7 @@ def fit(self, X=None, is_normal=False,
261261
elif self.screening_size > p:
262262
raise ValueError(
263263
"screening size should be smaller than X.shape[1].")
264-
elif self.screening_size < max(support_sizes):
264+
elif self.screening_size < np.nonzero(support_sizes)[0].max() + 1:
265265
raise ValueError(
266266
"screening size should be more than max(support_size).")
267267

@@ -290,11 +290,11 @@ def fit(self, X=None, is_normal=False,
290290
"number should be an positive integer and"
291291
" not bigger than X.shape[1].")
292292

293-
# Important_search
294-
if (not isinstance(self.important_search, int)
295-
or self.important_search < 0):
296-
raise ValueError(
297-
"important_search should be a non-negative number.")
293+
# # Important_search
294+
# if (not isinstance(self.important_search, int)
295+
# or self.important_search < 0):
296+
# raise ValueError(
297+
# "important_search should be a non-negative number.")
298298

299299
# A_init
300300
if A_init is None:
@@ -547,11 +547,11 @@ def fit(self, X, r, group=None, A_init=None):
547547
if self.splicing_type not in (0, 1):
548548
raise ValueError("splicing type should be 0 or 1.")
549549

550-
# Important_search
551-
if (not isinstance(self.important_search, int)
552-
or self.important_search < 0):
553-
raise ValueError(
554-
"important_search should be a non-negative number.")
550+
# # Important_search
551+
# if (not isinstance(self.important_search, int)
552+
# or self.important_search < 0):
553+
# raise ValueError(
554+
# "important_search should be a non-negative number.")
555555

556556
# A_init
557557
if A_init is None:

python/abess/functions.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def __call__(self, x):
7272
return value[0]
7373
return value
7474

75-
def __repr__(self):
76-
return "StepFunction(x=%r, y=%r, a=%r, b=%r)" % (
77-
self.x, self.y, self.a, self.b)
75+
# def __repr__(self):
76+
# return "StepFunction(x=%r, y=%r, a=%r, b=%r)" % (
77+
# self.x, self.y, self.a, self.b)
7878

7979

8080
class BreslowEstimator:
@@ -125,25 +125,25 @@ def fit(self, linear_predictor, event, time):
125125
np.exp(- self.cum_baseline_hazard_.y))
126126
return self
127127

128-
def get_cumulative_hazard_function(self, linear_predictor):
129-
r"""Predict cumulative hazard function.
130-
Parameters
131-
----------
132-
linear_predictor : array-like, shape = (n_samples,)
133-
Linear predictor of risk: `X @ coef`.
134-
Returns
135-
-------
136-
cum_hazard : ndarray, shape = (n_samples,)
137-
Predicted cumulative hazard functions.
138-
"""
139-
risk_score = np.exp(linear_predictor)
140-
n_samples = risk_score.shape[0]
141-
funcs = np.empty(n_samples, dtype=object)
142-
for i in range(n_samples):
143-
funcs[i] = StepFunction(x=self.cum_baseline_hazard_.x,
144-
y=self.cum_baseline_hazard_.y,
145-
a=risk_score[i])
146-
return funcs
128+
# def get_cumulative_hazard_function(self, linear_predictor):
129+
# r"""Predict cumulative hazard function.
130+
# Parameters
131+
# ----------
132+
# linear_predictor : array-like, shape = (n_samples,)
133+
# Linear predictor of risk: `X @ coef`.
134+
# Returns
135+
# -------
136+
# cum_hazard : ndarray, shape = (n_samples,)
137+
# Predicted cumulative hazard functions.
138+
# """
139+
# risk_score = np.exp(linear_predictor)
140+
# n_samples = risk_score.shape[0]
141+
# funcs = np.empty(n_samples, dtype=object)
142+
# for i in range(n_samples):
143+
# funcs[i] = StepFunction(x=self.cum_baseline_hazard_.x,
144+
# y=self.cum_baseline_hazard_.y,
145+
# a=risk_score[i])
146+
# return funcs
147147

148148
def get_survival_function(self, linear_predictor):
149149
r"""Predict survival function.
@@ -164,7 +164,8 @@ def get_survival_function(self, linear_predictor):
164164
y=np.power(self.baseline_survival_.y, risk_score[i]))
165165
return funcs
166166

167-
def _compute_counts(self ,event, time, order=None):
167+
@staticmethod
168+
def _compute_counts(event, time, order=None):
168169
"""Count right censored and uncensored samples at each unique time point.
169170
170171
Parameters

python/abess/utilities.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def categorical_to_dummy(x, classes=None):
6969
for i, x_i in enumerate(x):
7070
if x_i in classes:
7171
dummy_x[i, index[x_i]] = 1
72-
else:
73-
print(
74-
"Data {} (index {}) is not in classes.".format(
75-
x_i,
76-
i))
72+
# else:
73+
# print(
74+
# "Data {} (index {}) is not in classes.".format(
75+
# x_i,
76+
# i))
7777
return dummy_x

python/pytest/test_alg.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ def assert_reg(coef):
176176
# assert_fit(model1.coef_, model2.coef_) # TODO
177177
assert_reg(model2.coef_)
178178

179+
# survival function
180+
surv = model1.predict_survival_function(data.x)
181+
time_points = np.quantile(data.y[:, 0], np.linspace(0, 0.6, 100))
182+
surv[0](time_points)
183+
179184
@staticmethod
180185
def test_poisson():
181186
np.random.seed(9)
@@ -379,8 +384,12 @@ def test_PCA():
379384

380385
# ic
381386
for ic in ['aic', 'bic', 'ebic', 'gic']:
382-
model4 = abess.SparsePCA(support_size=support_size, ic_type=ic)
383-
model4.fit(X, is_normal=False)
387+
model = abess.SparsePCA(support_size=support_size, ic_type=ic)
388+
model.fit(X, is_normal=False)
389+
390+
# A_init
391+
model = abess.SparsePCA(support_size=support_size)
392+
model.fit(X, A_init=[0, 1, 2])
384393

385394
@staticmethod
386395
def test_gamma():
@@ -440,6 +449,10 @@ def test_RPCA():
440449
model4 = abess.RobustPCA(support_size=s, ic_type=ic)
441450
model4.fit(X, r=r)
442451

452+
# always select
453+
model5 = abess.RobustPCA(support_size=s, always_select=[1])
454+
model5.fit(X, r=r)
455+
443456
@staticmethod
444457
def test_ordinal():
445458
np.random.seed(0)

python/pytest/test_check.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,27 @@ def test_base():
272272
else:
273273
assert False
274274

275+
try:
276+
data = abess.make_glm_data(n=100, p=10, k=3, family='gaussian')
277+
model = abess.LinearRegression()
278+
model.fit(data.x, data.y)
279+
model.score(data.x[:, 1:], data.y)
280+
except ValueError as e:
281+
print(e)
282+
else:
283+
assert False
284+
275285
# lack of necessary parameter
276286
try:
287+
model = abess.LinearRegression()
277288
model.fit(X=[[1]])
278289
except ValueError as e:
279290
print(e)
280291
else:
281292
assert False
282293

283294
try:
295+
model = abess.LinearRegression()
284296
model.fit(y=[1])
285297
except ValueError as e:
286298
print(e)
@@ -361,6 +373,14 @@ def test_pca():
361373
else:
362374
assert False
363375

376+
try:
377+
model = abess.SparsePCA(screening_size=np.ones((100, 1)))
378+
model.fit(data)
379+
except ValueError as e:
380+
print(e)
381+
else:
382+
assert False
383+
364384
# screening_size
365385
model = abess.SparsePCA(screening_size=0)
366386
model.fit(data)
@@ -373,6 +393,14 @@ def test_pca():
373393
else:
374394
assert False
375395

396+
try:
397+
model = abess.SparsePCA(screening_size=1, support_size=2)
398+
model.fit(data)
399+
except ValueError as e:
400+
print(e)
401+
else:
402+
assert False
403+
376404
# lack of necessary parameter
377405
try:
378406
model.fit()
@@ -444,6 +472,38 @@ def test_pca():
444472
else:
445473
assert False
446474

475+
try:
476+
model1 = abess.SparsePCA(exchange_num=-1)
477+
model1.fit([[1]])
478+
except ValueError as e:
479+
print(e)
480+
else:
481+
assert False
482+
483+
try:
484+
model1 = abess.SparsePCA(thread=-1)
485+
model1.fit([[1]])
486+
except ValueError as e:
487+
print(e)
488+
else:
489+
assert False
490+
491+
try:
492+
model1 = abess.SparsePCA()
493+
model.fit([[1]], A_init=[[0, 1, 2]])
494+
except ValueError as e:
495+
print(e)
496+
else:
497+
assert False
498+
499+
try:
500+
model1 = abess.SparsePCA()
501+
model.fit([[1]], A_init=[-1])
502+
except ValueError as e:
503+
print(e)
504+
else:
505+
assert False
506+
447507
@staticmethod
448508
def test_rpca():
449509
model = abess.RobustPCA()
@@ -507,3 +567,43 @@ def test_rpca():
507567
print(e)
508568
else:
509569
assert False
570+
571+
try:
572+
model1 = abess.RobustPCA(support_size=[100])
573+
model1.fit([[1]], r=1)
574+
except ValueError as e:
575+
print(e)
576+
else:
577+
assert False
578+
579+
try:
580+
model1 = abess.RobustPCA()
581+
model1.fit([[1]], r=0.1)
582+
except ValueError as e:
583+
print(e)
584+
else:
585+
assert False
586+
587+
try:
588+
model1 = abess.RobustPCA(exchange_num=-1)
589+
model1.fit([[1]], r=1)
590+
except ValueError as e:
591+
print(e)
592+
else:
593+
assert False
594+
595+
try:
596+
model1 = abess.RobustPCA(splicing_type=-1)
597+
model1.fit([[1]], r=1)
598+
except ValueError as e:
599+
print(e)
600+
else:
601+
assert False
602+
603+
try:
604+
model1 = abess.RobustPCA(thread=-1)
605+
model1.fit([[1]], r=1)
606+
except ValueError as e:
607+
print(e)
608+
else:
609+
assert False

0 commit comments

Comments
 (0)