Skip to content

Commit

Permalink
Merge pull request #7 from jmbhughes/1.0.0
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
jmbhughes authored Aug 2, 2023
2 parents b2e6f86 + 9ae27f3 commit 9dfe037
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: codecov
name: ci
on: [push]
jobs:
run:
Expand All @@ -8,13 +8,13 @@ jobs:
os: [ubuntu-latest]
env:
OS: ${{ matrix.os }}
PYTHON: '3.7'
PYTHON: '3.10.12'
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7
python-version: "3.10.12"
- name: Generate coverage report
run: |
pip install ".[test]"
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build -s
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
12 changes: 3 additions & 9 deletions crcf/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import crcf.tree
import crcf.rule
import numpy as np
import pickle


class CombinationForest:
Expand Down Expand Up @@ -49,11 +48,8 @@ def save(self, path: str) -> None:
-------
None
"""
# TODO: change this to a more robust save method
if not path.lower().endswith('.pkl'):
raise RuntimeError("Save paths should end with .pkl")
with open(path, 'wb') as f:
pickle.dump(self, f)
raise NotImplementedError("Saving was removed for a pickle vulnerability.")


@classmethod
def load(cls, path: str) -> CombinationForest:
Expand All @@ -69,9 +65,7 @@ def load(cls, path: str) -> CombinationForest:
CombinationForest
the loaded tree
"""
with open(path, 'rb') as f:
forest = pickle.load(f)
return forest
raise NotImplementedError("Saving was removed for a pickle vulnerability.")

def depth(self, x: np.ndarray,
estimated: bool = True) -> np.ndarray:
Expand Down
15 changes: 4 additions & 11 deletions crcf/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from graphviz import Digraph
from .rule import Rule, AxisAlignedRule, NonAxisAlignedRule
from dataclasses import dataclass
import pickle


@dataclass(repr=False)
Expand Down Expand Up @@ -275,11 +274,7 @@ def save(self, path: str) -> None:
-------
None
"""
# TODO: change this to a more robust save method
if not path.lower().endswith('.pkl'):
raise RuntimeError("Save paths should end with .pkl")
with open(path, 'wb') as f:
pickle.dump(self, f)
raise NotImplementedError("Saving was removed for a pickle vulnerability.")

@classmethod
def load(cls, path: str) -> CombinationTree:
Expand All @@ -295,9 +290,7 @@ def load(cls, path: str) -> CombinationTree:
CombinationTree
the loaded tree
"""
with open(path, 'rb') as f:
tree = pickle.load(f)
return tree
raise NotImplementedError("Loading was removed for a pickle vulnerability.")

def depth(self, x: np.ndarray,
estimated: bool = True) -> float:
Expand Down Expand Up @@ -435,7 +428,7 @@ def score(self, x: np.ndarray,
if normalize:
disp = disp / (self.root.count - 1)
depths = depths / self.root.count
return depth_weight * depths + disp_weight * disp
return depth_weight * 1/depths + disp_weight * disp

def remove_by_node(self, node: Node) -> None:
"""Remove the specified node using RRCF rules
Expand Down Expand Up @@ -649,7 +642,7 @@ def score(self, x: np.ndarray, estimated: bool = False) -> np.ndarray:


class RobustRandomCutTree(CombinationTree):
def __init__(self, depth_limit: Optional[int] = None) -> None:
def __init__(self, depth_limit: Optional[int] = None) -> None:
super().__init__(depth_limit=depth_limit, rule_kind=AxisAlignedRule, rule_mode="biased")

def depth(self, x: np.ndarray,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "crcf"
version = "0.0.4"
version = "1.0.0"
authors = [
{ name="J. Marcus Hughes", email="[email protected]"}
]
Expand Down

0 comments on commit 9dfe037

Please sign in to comment.