Skip to content

Commit

Permalink
[MNT] Modify details
Browse files Browse the repository at this point in the history
  • Loading branch information
bxdd committed Apr 4, 2023
1 parent c9f3a67 commit 99128f9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 41 deletions.
Binary file modified docs/_static/img/classes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/examples1/example_rkme.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
for i in range(10):
data_X[i, i] = np.nan
spec1 = specification.utils.generate_rkme_spec(X=data_X, gamma=0.1, cuda_idx=-1)
spec2 = specification.rkme.RKMESpecification()
spec2 = specification.rkme.RKMEStatSpecification()
spec1.generate_stat_spec_from_data(data_X)
spec1.save("spec.json")

Expand Down
3 changes: 2 additions & 1 deletion examples/examples2/svm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import joblib
import numpy as np
from learnware.model import BaseModel


class SVM:
class SVM(BaseModel):
def __init__(self):
dir_path = os.path.dirname(os.path.abspath(__file__))
self.model = joblib.load(os.path.join(dir_path, "svm.pkl"))
Expand Down
4 changes: 2 additions & 2 deletions learnware/learnware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


class Learnware:
def __init__(self, id: str, name: str, model: BaseModel, specification: Specification, desc: str):
def __init__(self, id: str, name: str, model: Union[BaseModel, dict], specification: Specification, desc: str):
self.id = id
self.name = name
self.model = model
self.model = self._import_model(model)
self.specification = specification
self.desc = desc

Expand Down
5 changes: 2 additions & 3 deletions learnware/market/anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from typing import Tuple, Any, List, Union, Dict

from ..learnware import Learnware
from .base import BaseMarket
from .easy import EasyUserInfo
from .base import BaseMarket, BaseUserInfo


class AnchoredUserInfo(EasyUserInfo):
class AnchoredUserInfo(BaseUserInfo):
"""
User Information for searching learnware (add the anchor design)
Expand Down
27 changes: 25 additions & 2 deletions learnware/market/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,34 @@
class BaseUserInfo:
"""User Information for searching learnware"""

def __init__(self, id: str, semantic_spec: dict = dict(), stat_info: dict = dict()):
"""Initializing user information
Parameters
----------
id : str
user id
semantic_spec : dict, optional
semantic_spec selected by user, by default dict()
stat_info : dict, optional
statistical information uploaded by user, by default dict()
"""
self.id = id
self.semantic_spec = semantic_spec
self.stat_info = stat_info

def get_semantic_spec(self) -> dict:
raise NotImplementedError("get_semantic_spec is Not Implemented")
"""Return user semantic specifications
Returns
-------
dict
user semantic specifications
"""
return self.semantic_spec

def get_stat_info(self, name: str):
raise NotImplementedError("get_stat_info is Not Implemented")
return self.stat_info.get(name, None)


class BaseMarket:
Expand Down
33 changes: 2 additions & 31 deletions learnware/market/easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,6 @@
from ..specification import RKMEStatSpecification


class EasyUserInfo(BaseUserInfo):
def __init__(self, id: str, semantic_spec: dict = dict(), stat_info: dict = dict()):
"""Initializing user information
Parameters
----------
id : str
user id
semantic_spec : dict, optional
semantic_spec selected by user, by default dict()
stat_info : dict, optional
statistical information uploaded by user, by default dict()
"""
self.id = id
self.semantic_spec = semantic_spec
self.stat_info = stat_info

def get_semantic_spec(self) -> dict:
"""Return user semantic specifications
Returns
-------
dict
user semantic specifications
"""
return self.semantic_spec

def get_stat_info(self, name: str):
return self.stat_info.get(name, None)


class EasyMarket(BaseMarket):
def __init__(self):
"""Initializing an empty market"""
Expand Down Expand Up @@ -164,6 +133,8 @@ def match_semantic_spec(semantic_spec1, semantic_spec2):
return match_learnwares

match_learnwares = search_by_semantic_spec()
# return match_learnwares
# TODO:

def delete_learnware(self, id: str) -> bool:
if not id in self.learnware_list:
Expand Down
2 changes: 1 addition & 1 deletion learnware/specification/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def load(self, filepath: str):
class Specification:
def __init__(self, semantic_spec=None):
self.semantic_spec = semantic_spec
self.stat_spec = BaseStatSpecification() # stat_spec should be dict
self.stat_spec = {} # stat_spec should be dict

def get_stat_spec(self):
return self.stat_spec
Expand Down

0 comments on commit 99128f9

Please sign in to comment.