text:
"""
factorial: This module contains tools for designing factorial experiments. Full factorial
experiments (where every combination of treatments is explored) and partial factorial (where only a
fraction of combinations are explored). Partial factorial experiments are sometimes referred to as
fractional factorial experiments.

The factorial designs here are meant to yield balanced and orthogonal designs. An experimental
design is orthogonal if the effects of any factor (i.e. factor A) balance out (sum to zero) across
the effects of the other factors (i.e. factors B and C). In other words, if A is orthogonal to B
and C, then the measurement of factors B and C will not be biased by the effect size fo A. A
balanced design assumes equal sample sizes across att cohorts / test cells.

One quick check of orthogonality for a 2 level design is to take the sum of the columns of the
design. They should all sum to 0. See below:
>>> design_partial_factorial(factors=6, res=4).sum(axis=0)

If possible, all combinations (rows) in these designs should be run in a random order, or in
parallel using proper randomization of cohort assignment.

Recommended import style:
>>> from lind.design import factorial

"""

import logging
from typing import Union, List, Optional

from itertools import product, combinations
from fractions import Fraction

from numpy import full, arange, vectorize, ndarray, array_str, asarray
from scipy.special import binom

from pandas import DataFrame, read_csv
from patsy import dmatrix  # pylint: disable=no-name-in-module

from lind._utilities import _check_int_input
from lind import _sfap

# set logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# define public functions (ignored by jupyter notebooks)
__all__ = [
    'design_full_factorial',
    'design_partial_factorial',
    'fetch_partial_factorial_design'
]

####################################################################################################

def _array_to_string(arr_like: Union[List, ndarray]) -> ndarray:
    """Utility for converting experiment design string into an array of factors"""
    return array_str(asarray(arr_like)).replace("[", "").replace("]", "")

def _k_combo(k: int, res: int) -> int:
    """The number of combinations of k factors given a specific resolution"""
    return binom(
        full(k - res + 1, k),
        arange(res - 1, k, 1)
    ).sum() + k

_k_combo_vec = vectorize(_k_combo, excluded=['res'],
                         doc="The number of combinations of k factors given a specific resolution")

####################################################################################################

def design_full_factorial(factors: List[List],
                          factor_names: Optional[List[str]] = None) -> DataFrame:
    """
    design_full_factorial

    This function helps create a full factorial experiment design. Given how easy it is to design a
    full factorial experiment once the factors and levels have been specified, this is more of a
    convenience function.

    Parameters
    ----------
    factors : List[List]
        a list of lists representing factors and levels
    factor_names : List[str], optional
        a list of names for the factors in the first argument. Must share the order of the first
        argument.

    Returns
    -------
    pd.DataFrame

    Examples
    --------
    >>> # create full factorial design for a 2 level 3 factor experiment
    >>> design_df = design_full_factorial(factors=[[-1, 1], [-1,1], [-1, 1]],
    >>>     factor_names=["factor_one", "factor_two", "factor_three"])

    """

    assert factor_names is None or len(factor_names) == len(factors), \
        "The length of factor_names must match the length of factors."
    factor_names = factor_names if factor_names is not None else \
        ["x{}".format(i) for i in range(len(factors))]
    return DataFrame(data=list(product(*factors)), columns=factor_names)

def design_partial_factorial(k: int, res: int) -> DataFrame:
    """
    design_partial_factorial

    This function helps design 2 level partial factorial experiments. These experiments are often
    described using the syntax l**(k-p) where l represents the level of each factor, k represents
    the total number of factors considered, and p represents a scaling factor relative to the full
    factorial design.

    This function assumes that l=2. Users are not asked to set p, instead the user sets a minimum
    desired resolution for their experiment. Resolution describes the kind of aliasing incurred by
    scaling down from a full to a partial factorial design. Higher resolutions have less potential
    aliasing (confounding).

    Resolution number is determined through the defining relation of the partial factorial design.
    For the 6 factor design 2**(6-p) with factors ABCDEF, example defining relations (I) are shown
    below. The resolution cannot exceed the number of factors in the experiment. So a 6 factor
    experiment can be at most a resolution 6 (otherwise it would be a full factorial experiment).

        * Res I: I = A
        * Res II: I = AB
        * Res III: I = ABC
        * Res IV: I = ABCD
        * Res V: I = ABCDE
        * Res VI: I = ABCDEF

    Practically we tend to use resolution III-, IV- and V-designs.

        * Res I: Cannot distinguish between levels within main effects (not useful).
        * Res II: Main effects may be aliased with other main effects (not useful).
        * Res III: Main effects may be aliased with two-way interactions.
        * Res IV: Two-way interactions may be aliased with each other.
        * Res V: Two-way interactions may be aliased with three-way interactions.
        * Res VI: Three-way interactions may be aliased with each other.

    Parameters
    ----------
    k : int
        the total number of factors considered in the experiment
    res : int
        the desired minimum resolution of the experiment

    Returns
    -------
    pd.DataFrame
        A dataframe with the partial factorial design

    Examples
    --------
    >>> # create partial factorial design for a 2 level 4 factor resolution III experiment
    >>> design_df = design_partial_factorial(k=4, res=3)

    """

    _check_int_input(k, "k")
    _check_int_input(res, "res")
    assert res <= k, "Resolution must be smaller than or equal to the number of factors."

    # Assume l=2 and use k specified by user to solve for p in design
    n = arange(res - 1, k, 1)
    k_minus_p = k - 1 if res == k else n[~(_k_combo_vec(n, res) < k)][0]

    logging.info("Partial Factorial Design: l=2, k={}, p={}".format(k, k - k_minus_p))
    logging.info("Ratio to Full Factorial Design: {}".format(Fraction(2**k_minus_p / 2**k)))

    # identify the main effects and interactions for the design

    main_factors = arange(k_minus_p)
    clean = lambda x: x.replace("  ", " ").strip(" ").replace(" ", ":")
    interactions = [clean(_array_to_string(main_factors))] if res == k else \
        [
            clean(_array_to_string(c))
            for r in range(res - 1, k_minus_p)
            for c in combinations(main_factors, r)
        ][:k - k_minus_p]

    # combine main effects and interactions into a single design string (format inspired by patsy)
    factors = " ".join([_array_to_string(main_factors)] + interactions)
    logging.info("Design string: {}".format(factors))

    main_factors = [i for i in factors.split(" ") if i and ":" not in i]
    two_level_full_factorial = [[-1, 1] for _ in main_factors]
    full_factorial_design = design_full_factorial(two_level_full_factorial)

    interactions = [
        ["x" + i for i in j.split(":")]
        for j in [i for i in factors.split(" ") if i and ":" in i]
    ]

    design = "+".join(full_factorial_design.columns.tolist() + [":".join(i) for i in interactions])
    partial_factorial_design = dmatrix(design, full_factorial_design, return_type='dataframe').drop(
        columns=["Intercept"], axis=1)

    partial_factorial_design.columns = \
        ["x{}".format(i) for i in range(partial_factorial_design.shape[1])]

    return partial_factorial_design

####################################################################################################

def fetch_partial_factorial_design(design_name: str = "toc") -> DataFrame:
    """
    fetch_partial_factorial_design

    The function design_partial_factorial auto generates partial factorial designs using an
    algorithm. We validate that algorithm in our unit tests by comparing against known designs
    from popular experimental design textbooks. For those that want to use the designs from
    these books rather than the auto-generated designs, please use thos function.

    There are multiple ways to generate certain designs given a fixed k and p
    (using formula l**k-p). Both fetch_partial_factorial_design and design_partial_factorial
    deterministically return designs, but there are typically other ways to formulate these designs
    if the user would like to work it out on their own.

    Parameters
    ----------
    design_name : str
        the name of the design to fetch; to see available designs input `toc`

    Returns
    -------
    pd.DataFrame
        experiment design or toc of available designs

    Examples
    --------
    >>> table_of_contents_of_designs = fetch_partial_factorial_design("toc")
    >>> design = fetch_partial_factorial_design("2**3-1")

    References
    ----------
    NIST
        * Section 5.3.3.4.7 of the Engineering Statistics Handbook
    Box, Hunter, & Hunter
        * Statistics For Experimentors
    Taguchi
        * Systems Of Experimental Design, VOL. 2

    Notes
    -----
    * 2**3-1 is equivalent to a Taguchi L4 design
    * 2**15-11 is equivalent to a Taguchi L16 design
    * 2**31-26 is equivalent to a Taguchi L32 design

    """

    assert isinstance(design_name, str), "Input design_name must be a string."
    design_name = design_name.lower().strip() + ".csv"
    if _sfap is None:
        raise Exception("Missing dependency lind-static-resources")
    try:
        return read_csv(_sfap+"/factorial/"+design_name, index_col=0)
    except FileNotFoundError as exception:
        logging.error(exception)
        raise ValueError("Please input a valid design. `{}` not found. "
                         "See docstring for help.".format(design_name[:-4]))

max_stars_repo_name: James-Montgomery/lind

max_issues_repo_name: James-Montgomery/lind

max_forks_repo_name: James-Montgomery/lind

reason: from numpy,from scipy


text:
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import logging
import shlex
import subprocess

import numpy as np
import os
from PIL import Image

from .exceptions import ProgramNotFoundError, DirectoryDoesNotExist

logger = logging.getLogger("common")

def html2image(exe_path, exe_args, html_content, out_path):
    """
    convert html to image with `wkhtmltoimage` tools

    :param exe_path: wkhtmltoimage path
    :param exe_args: wkhtmltoimage args or options
    :param html_content: utf-8 html source code
    :param out_path: output image path
    :return: bool
    """
    if not os.path.exists(exe_path):
        raise ProgramNotFoundError("%s not exists", exe_path)
    parent_dir = os.path.dirname(out_path)
    if not os.path.exists(parent_dir):
        raise DirectoryDoesNotExist("%s not exist", parent_dir)

    try:
        params = [exe_path]
        args = shlex.split(exe_args)
        params.extend(args)
        params += ["-", out_path]

        process = subprocess.Popen(params, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        out, err = process.communicate(html_content)
        if not err:
            return True
        logging.error(err)
        return False
    except Exception as e:
        logging.error(str(e))
        return False

def change_background_color(self, filepath, color=(255, 255, 255)):
    """
    Change background white color to color

    :param filepath:
    :param color:
    :return:
    """
    im = Image.open(filepath)
    im = im.convert("RGBA")

    data = np.array(im)  # "data" is a height x width x 4 numpy array
    red, green, blue, alpha = data.T  # Temporarily unpack the bands for readability

    # Replace white with red... (leaves alpha values alone...)
    white_areas = (red == 255) & (blue == 255) & (green == 255)
    data[..., :-1][white_areas.T] = color  # Transpose back needed
    im2 = Image.fromarray(data)
    im2.save(filepath)

def suit_cropping(self, filein, fileout=None, watermark=True):
    """
    Crop Image
    :param filein:
    :param fileout:
    :param watermark:
    :return:
    """
    im_in = Image.open(filein)

    if im_in.mode == "RGB":
        im = im_in.convert("L")
    if im_in.mode == "RGBA":
        im = im_in.convert("L")
    elif im_in.mode == "P":
        im = im_in.convert("L")
    else:
        im = im_in
    data = list(im.getdata())

    w, h = im.size  # width, height
    # print "size: (%d, %d)" % (w, h)
    if watermark:
        h -= 10
        data = data[:h * w]

    # s: start,  e: end
    s1_min = w - 1
    e1_max = 0
    s2_min = h - 1
    e2_max = 0
    s1_tmp = w - 1
    e1_tmp = 0

    s2_and_e2_tmp = 0

    for i, d in enumerate(data):
        x = i % w
        y = i // w
        if x == 0:
            if s1_min > s1_tmp:
                s1_min = s1_tmp
            if e1_max < e1_tmp:
                e1_max = e1_tmp

            if s2_and_e2_tmp:
                if s2_min > y:
                    s2_min = y
                if e2_max < y:
                    e2_max = y
            s1_tmp = w - 1
            e1_tmp = 0
            s2_and_e2_tmp = 0

        if d != 255:
            e1_tmp = x
            if s1_tmp == w - 1:
                s1_tmp = x
            s2_and_e2_tmp = 1

    widening_w = int((e1_max - s1_min) * 0.05)
    widening_h = int((e2_max - s2_min) * 0.05)

    widening_limit = True
    if widening_limit:
        limit = 22
        widening_w = limit if widening_w > limit else widening_w
        widening_h = limit if widening_h > limit else widening_h

    s1_crop = s1_min - widening_w if s1_min - widening_w > 0 else 0
    e1_crop = e1_max + widening_w if e1_max + widening_w < w else w - 1
    s2_crop = s2_min - widening_h if s2_min - widening_h > 0 else 0
    e2_crop = e2_max + widening_h if e2_max + widening_h < h else h - 1
    region = im_in.crop((s1_crop, s2_crop, e1_crop, e2_crop))

    region.save(fileout or filein)

ext: py

max_stars_repo_name: smileboywtu/RR

max_issues_repo_name: smileboywtu/RR

max_forks_repo_name: smileboywtu/RR

reason: import numpy


text:
"""
A set of objects that allows declarative specification of a model
including training patterns, sheets and projections.

The components of a model specification can be individually inspected,
modified, resolved or instantiated.
"""

from collections import OrderedDict

import param
from holoviews.interface.collector import AttrTree

import topo

class Specification(param.Parameterized):
    """
    Specifications are templates for sheet or projection objects which
    may be resolved to the corresponding simulation object once
    instantiated.

    All specifications have the following attribute:

    :'parameters': Keyword argument dictionary specifying which
    parameters should be passed to the sheet or projection object.
    """

    def update(self, **params):
        """
        Convenience method to easy update specification parameters.
        """
        self.parameters.update(params)

    @property
    def modified_parameters(self):
        "Dictionary of modified specification parameters"
        return {k:v for k, v in self.parameters.items()
                if self.default_parameters[k] != v}

    @property
    def resolved_type(self):
        return self._object_type

    def resolve(self):
        """
        Returns the object in topo.sim corresponding to this object,
        typically a Sheet or a Projection.

        The appropriate object must be available in topo.sim.
        """
        raise NotImplementedError

    def __lt__(self, other):
        return self.sort_precedence < other.sort_precedence

    def __eq__(self, other):
        return self.sort_precedence == other.sort_precedence

    def __init__(self, object_type):
        self._object_type = object_type
        self.parameters = {}
        self.sort_precedence = 0

        if not hasattr(object_type,'params'):
            self.default_parameters = {}
        else:
            for param_name, default_value in object_type.params().items():
                self.parameters[param_name]=default_value.default
            self.default_parameters = dict(**self.parameters)

    def summary(self, printed=True):
        """
        Generate a succinct summary of the Specification object. If
        printed is set to True, the summary is printed, otherwise it
        is returned as a string.
        """
        raise NotImplementedError

    def __getitem__(self, key):
        "Convenient property access."
        return self.properties[key]

    def keys(self):
        "The list of available property keys."
        return self.properties.keys()

    def items(self):
        "The property items."
        return self.properties.items()

class ArraySpec(Specification):
    """
    A simple specification used to resolve numpy arrays relative to a
    Topographica simulation (i.e. topo.sim). This class is primarily
    aimed for specifying arrays to a Collector.
    """

    def __init__(self, pathspec, properties={}):
        """
        ArraySpec uses a fairly unsophisticated implementation, making
        use of eval to resolve the desired array.

       :'pathspec': A string specifying how to access the array
                    relative to topo.sim.
       :'properties': Optional specification of array properties
        """
        import numpy
        self.pathspec = pathspec
        super(ArraySpec,self).__init__(numpy.ndarray)
        self.properties = OrderedDict(properties)

    def resolve(self):
        from topo import sim   # pyflakes:ignore (import for eval)
        return eval("sim.%s" % self.pathspec)

    def __call__(self):
        raise NotImplementedError

    def __str__(self):
        return "topo.sim.%s" % self.pathspec

    def summary(self, printed=True):
        summary = "%s : Numpy array" % self
        if printed: print summary
        else:       return summary

    def __repr__(self):
        properties_repr = ', '.join("%r:%r" % (k,v) for (k,v)
                                    in self.properties.items())
        return "ArraySpec(%r, {%s})" % (self.pathspec, properties_repr)

class SheetSpec(Specification):
    """
    SheetSpec acts as a template for sheet objects.
    """

    name_ordering = ['eye','level', 'cone', 'polarity',
                     'SF','opponent','surround']

    @property
    def level(self):
        return self.properties['level']

    def __init__(self, sheet_type, properties):
        """
        Initialize a SheetSpec object of a certain Sheet type with the
        given properties.

       :'sheet_type': Subclass of topo.base.sheet.Sheet.
       :'properties': Dictionary specifying the properties of the
       sheet. There must be a value given for the key 'level'.
        """
        super(SheetSpec,self).__init__(sheet_type)

        if 'level' not in properties:
            raise Exception("SheetSpec always requires 'level' property.")

        properties = [(k, properties[k]) for k in self.name_ordering
                      if k in properties]

        self.sheet_type = sheet_type
        self.properties = OrderedDict(properties)

    def resolve(self):
        from topo import sim
        return sim[str(self)]

    def __call__(self):
        """
        Instantiate the sheet and register it in topo.sim.
        """
        properties = dict(self.parameters['properties'], **self.properties)
        topo.sim[str(self)]=self.sheet_type(**dict(self.parameters,
                                                   properties=properties))

    def __str__(self):
        """
        Returns a string representation of the SheetSpec from the
        properties values.
        """
        name=''
        for prop in self.properties.itervalues():
            name+=str(prop)
        return name

    def summary(self, printed=True):
        summary = "%s : %s" % (self, self.sheet_type.name)
        if printed: print summary
        else:       return summary

    def __repr__(self):
        type_name = self.sheet_type.__name__
        properties_repr = ', '.join("%r:%r" % (k,v) for (k,v)
                                    in self.properties.items())
        return "SheetSpec(%s, {%s})" % (type_name, properties_repr)

class ProjectionSpec(Specification):
    """
    ProjectionSpec acts as a template for projection objects.
    """

    def __init__(self, projection_type, src, dest):
        """
        Initialize a ProjectionSpec object of a certain Projection
        type with the given src and dest SheetSpecs.

       :'projection_type': Subclass of topo.base.projection.Projection
       :'src': SheetSpec of the source sheet
       :'dest': SheetSpec of the destination sheet
        """
        super(ProjectionSpec, self).__init__(projection_type)

        self.projection_type = projection_type
        self.src = src
        self.dest = dest
        self.properties = {}

        # These parameters are directly passed into topo.sim.connect()!
        ignored_keys = ['src', 'dest']
        self.parameters = dict((k,v) for (k,v) in self.parameters.items()
                               if k not in ignored_keys)

    def resolve(self):
        from topo import sim
        return sim[str(self.dest)].projections(self.parameters['name'])

    def __call__(self):
        """
        Instantiate the projection and register it in topo.sim.
        """
        topo.sim.connect(str(self.src),str(self.dest),
                         self.projection_type,
                         **self.parameters)

    def __str__(self):
        return str(self.dest)+'.' + self.parameters['name']

    def summary(self, printed=True):
        summary = "%s [%s -> %s] : %s" % (self, self.src, self.dest,
                                          self.projection_type.name)
        if printed: print summary
        else:       return summary

    def __repr__(self):
        type_name = self.projection_type.__name__
        return "ProjectionSpec(%s, %r, %r)" % (type_name, self.src, self.dest)

class ModelSpec(Specification):
    """
    ModelSpec acts as a template for Topographica model including
    training patterns, sheets and projections.
    """

    def __init__(self, model, properties):
        self.training_patterns = AttrTree()
        self.sheets = AttrTree()
        self.projections = AttrTree()

        self._instantiated = False

        self.properties = properties
        super(ModelSpec, self).__init__(model)
        self.model= model

    def resolve(self):
        from topo import sim     # pyflakes:ignore (needed for eval)
        return eval('sim.model')

    def __call__(self, instantiate_options=True, verbose=False):
        """
        Instantiates all sheets or projections in self.sheets or
        self.projections and registers them in the topo.sim instance.

        If instantiate_options=True, all items are initialised
        instantiate_options can also be a list, whereas all list items
        of available_instantiate_options are accepted.

        Available instantiation options are: 'sheets' and
        'projections'.

        Please consult the docstring of the Model class for more
        information about each instantiation option.
        """
        msglevel = self.message if verbose else self.debug

        if self._instantiated:
            msglevel('ModelSpec %r already instantiated. Returning.' % self.model.name)
            return

        available_instantiate_options = ['sheets','projections']
        if instantiate_options==True:
            instantiate_options=available_instantiate_options

        if 'sheets' in instantiate_options:
            for sheet_spec in self.sheets.path_items.itervalues():
                msglevel('Level ' + sheet_spec.level + ': Sheet ' + str(sheet_spec))
                sheet_spec()

        if 'projections' in instantiate_options:
            for proj in sorted(self.projections):
                msglevel('Match: ' + proj.matchname + ': Connection ' + str(proj.src) + \
                             '->' + str(proj.dest) + ' ' + proj.parameters['name'])
                proj()
        self._instantiated = True

    def summary(self, printed=True):
        name = self.model.__class__.__name__
        heading_line = '=' * len(name)
        summary = [heading_line, name, heading_line, '']

        for sheet_spec in sorted(self.sheets):
            summary.append(sheet_spec.summary(printed=False))
            projections = [proj for proj in self.projections
                           if str(proj.dest)==str(sheet_spec)]
            for projection_spec in sorted(projections, key=lambda p: str(p)):
                summary.append("   " + projection_spec.summary(printed=False))
            summary.append('')

        if printed: print "\n".join(summary)
        else:       return "\n".join(summary)

    def __str__(self):
        return self.model.__class__.__name__

    def _repr_pretty_(self, p, cycle):
        p.text(self.summary(printed=False))

    def modifications(self, components=['model', 'sheets', 'projections']):
        """
        Display the names of all modified parameters for the specified
        set of components.

        By default all modified parameters are listed - first with the
        model parameters, then the sheet parameters and lastly the
        projection parameters.
        """
        mapping = {'model': [self],
                   'sheets':self.sheets,
                   'projections':self.projections}

        lines = []
        for component in components:
            heading = "=" * len(component)
            lines.extend([heading, component.capitalize(), heading, ''])
            specs = mapping[component]
            padding = max(len(str(spec)) for spec in specs)
            for spec in sorted(specs):
                modified = [str(el) for el in sorted(spec.modified_parameters)]
                lines.append("%s : [%s]" % (str(spec).ljust(padding), ", ".join(modified)))
            lines.append('')
        print "\n".join(lines)


text:
import pandas as pd
import numpy as np
import click
import os

from planet_emu import util, predict

@click.command()
@click.option(
    "-ls",
    "--loss",
    show_default=True,
    default="mean_absolute_percentage_error",
    help="Loss function for model",
)
@click.option(
    "-lr",
    "--learning_rate",
    show_default=True,
    default=0.001,
    help="Learning rate of the model",
)
@click.option(
    "-e",
    "--epochs",
    show_default=True,
    default=100,
    help="Number of epochs to train",
)
@click.option(
    "-o",
    "--overwrite",
    is_flag=True,
    show_default=True,
    default=False,
    help="Overwrite existing model",
)
def main(
    loss: str,
    learning_rate: float,
    epochs: int,
    overwrite: bool,
) -> None:
    dataset = pd.read_csv("data/csv/features.csv")
    dataset = dataset.drop(columns=["fips_code"])

    train_dataset, test_dataset = predict.split_dataset(dataset)
    train_features, train_labels = predict.split_features(train_dataset, "ndvi")
    test_features, test_labels = predict.split_features(test_dataset, "ndvi")

    if os.path.exists("data/model/linear/assets") and not overwrite:
        linear_model = predict.load_model("data/model/linear")
    else:
        linear_model, hist = predict.get_model(
            train_features,
            train_labels,
            loss=loss,
            learning_rate=learning_rate,
            epochs=epochs,
            linear=True,
        )
        util.to_csv(hist, "linear_model_history")
        linear_model.save("data/model/linear")

    linear_features = test_features.copy()
    linear_features["ndvi_prediction"] = linear_model.predict(linear_features).flatten()
    linear_features["ndvi_real"] = test_labels
    linear_features = linear_features.loc[:, ["ndvi_prediction", "ndvi_real"]]
    util.to_csv(linear_features, "linear_model_predictions")

    evaluation = predict.get_evaluation(linear_model, test_features, test_labels)
    print("Linear Model - Mean Absolute Percent Error:", evaluation)

    feature_names = train_features.columns
    feature_weights = np.array(linear_model.layers[1].kernel)

    weights_df = pd.DataFrame(
        {name: weight for name, weight in zip(feature_names, feature_weights)}
    ).T.reset_index()
    weights_df.columns = ["feature", "weight"]
    weights_df["weight_abs"] = abs(weights_df["weight"])
    weights_df["effect"] = weights_df["weight"].apply(
        lambda x: "pos" if x > 0 else "neg"
    )
    weights_df = weights_df.sort_values("weight_abs", ascending=False)
    util.to_csv(weights_df, "linear_model_weights")

    if os.path.exists("data/model/dnn/assets") and not overwrite:
        dnn_model = predict.load_model("data/model/dnn")
    else:
        dnn_model, hist = predict.get_model(
            train_features,
            train_labels,
            loss=loss,
            learning_rate=learning_rate,
            epochs=epochs,
            linear=False,
        )
        util.to_csv(hist, "dnn_model_history")
        dnn_model.save("data/model/dnn")

    dnn_features = test_features.copy()
    dnn_features["ndvi_prediction"] = dnn_model.predict(dnn_features).flatten()
    dnn_features["ndvi_real"] = test_labels
    dnn_features = dnn_features.loc[:, ["ndvi_prediction", "ndvi_real"]]
    util.to_csv(dnn_features, "dnn_model_predictions")

    evaluation = predict.get_evaluation(dnn_model, test_features, test_labels)
    print("Deep Nueral Network Model - Mean Absolute Percent Error:", evaluation)

if __name__ == "__main__":
    main()

max_stars_repo_name: danmcfan/planet-emu

max_issues_repo_name: danmcfan/planet-emu

max_forks_repo_name: danmcfan/planet-emu


text:
from __future__ import print_function

import os
import os.path as osp

import cv2
import numpy as np
import scipy.io as sio
import torch
import torchvision.transforms as tvt
from PIL import Image
from torch.utils import data
from skimage import io
from tqdm import tqdm

from ...utils.segmentation.render import render
from ...utils.segmentation.transforms import \
  pad_and_or_crop, random_affine, custom_greyscale_numpy

__all__ = ["DC"]

RENDER_DATA = False

class _DC(data.Dataset):
  """Base class
  This contains fields and methods common to all Potsdam datasets:
  PotsdamFull (6)
  PotsdamFew (3)

  """

  def __init__(self, config=None, split=None, purpose=None, preload=False):
    super(_DC, self).__init__()

    self.split = split
    self.purpose = purpose

    self.root = config.dataset_root

    self.single_mode = hasattr(config, "single_mode") and config.single_mode

    self.CLASS_DICT = {0: 0, 1: 0, 2: 1, 3: 2, 4: 3, 5: 4}

    # always used (labels fields used to make relevancy mask for train)
    self.gt_k = config.gt_k
    self.pre_scale_all = config.pre_scale_all
    self.pre_scale_factor = config.pre_scale_factor
    self.input_sz = config.input_sz

    self.include_rgb = config.include_rgb
    self.no_sobel = config.no_sobel

    # only used if purpose is train
    if purpose == "train":
      self.use_random_scale = config.use_random_scale
      if self.use_random_scale:
        self.scale_max = config.scale_max
        self.scale_min = config.scale_min

      self.jitter_tf = tvt.ColorJitter(brightness=config.jitter_brightness,
                                       contrast=config.jitter_contrast,
                                       saturation=config.jitter_saturation,
                                       hue=config.jitter_hue)

      self.flip_p = config.flip_p  # 0.5

      self.use_random_affine = config.use_random_affine
      if self.use_random_affine:
        self.aff_min_rot = config.aff_min_rot
        self.aff_max_rot = config.aff_max_rot
        self.aff_min_shear = config.aff_min_shear
        self.aff_max_shear = config.aff_max_shear
        self.aff_min_scale = config.aff_min_scale
        self.aff_max_scale = config.aff_max_scale

    self.preload = preload

    self.files = []
    self.images = []
    self.labels = []

    self._set_files()

    if self.preload:
      self._preload_data()

    cv2.setNumThreads(0)

  def _set_files(self):
    raise NotImplementedError()

  def _load_data(self, image_id):
    raise NotImplementedError()

  def _prepare_train(self, index, img):
    # This returns gpu tensors.
    # label is passed in canonical [0 ... 181] indexing

    img = img.astype(np.float32)

    # shrink original images, for memory purposes
    # or enlarge
    if self.pre_scale_all:
      img = cv2.resize(img, dsize=None, fx=self.pre_scale_factor,
                       fy=self.pre_scale_factor,
                       interpolation=cv2.INTER_LINEAR)

    # basic augmentation transforms for both img1 and img2
    if self.use_random_scale:
      # bilinear interp requires float img
      scale_factor = (np.random.rand() * (self.scale_max - self.scale_min)) + \
                     self.scale_min
      img = cv2.resize(img, dsize=None, fx=scale_factor, fy=scale_factor,
                       interpolation=cv2.INTER_LINEAR)

    # random crop to input sz
    img, coords = pad_and_or_crop(img, self.input_sz, mode="random")

    # make img2 different from img1 (img)

    # tf_mat can be:
    # *A, from img2 to img1 (will be applied to img2's heatmap)-> img1 space
    #   input img1 tf: *tf.functional or pil.image
    #   input mask tf: *none
    #   output heatmap: *tf.functional (parallel), inverse of what is used
    #     for inputs, create inverse of this tf in [-1, 1] format

    # B, from img1 to img2 (will be applied to img1's heatmap)-> img2 space
    #   input img1 tf: pil.image
    #   input mask tf: pil.image (discrete)
    #   output heatmap: tf.functional, create copy of this tf in [-1,1] format

    # tf.function tf_mat: translation is opposite to what we'd expect (+ve 1
    # is shift half towards left)
    # but rotation is correct (-sin in top right = counter clockwise)

    # flip is [[-1, 0, 0], [0, 1, 0], [0, 0, 1]]
    # img2 = flip(affine1_to_2(img1))
    # => img1_space = affine1_to_2^-1(flip^-1(img2_space))
    #               = affine2_to_1(flip^-1(img2_space))
    # so tf_mat_img2_to_1 = affine2_to_1 * flip^-1 (order matters as not diag)
    # flip^-1 = flip

    # no need to tf label, as we're doing option A, mask needed in img1 space
    # converting to PIL does not change underlying np datatype it seems

    # images are RGBIR. We don't want to jitter or greyscale the IR part

    img1 = Image.fromarray(img.astype(np.uint8))

    # (img2) do jitter, no tf_mat change
    img2 = self.jitter_tf(img1)  # not in place, new memory
    img1 = np.array(img1)
    img2 = np.array(img2)

    # channels still last
    # channels still last
    if not self.no_sobel:
      img1 = custom_greyscale_numpy(img1, include_rgb=self.include_rgb)
      img2 = custom_greyscale_numpy(img2, include_rgb=self.include_rgb)

    img1 = img1.astype(np.float32) / 255.
    img2 = img2.astype(np.float32) / 255.
    img1 = torch.from_numpy(img1).permute(2, 0 ,1).cuda()
    img2 = torch.from_numpy(img2).permute(2, 0, 1).cuda()

    # (img2) do affine if nec, tf_mat changes
    if self.use_random_affine:
      affine_kwargs = {"min_rot": self.aff_min_rot, "max_rot": self.aff_max_rot,
                       "min_shear": self.aff_min_shear,
                       "max_shear": self.aff_max_shear,
                       "min_scale": self.aff_min_scale,
                       "max_scale": self.aff_max_scale}
      img2, affine1_to_2, affine2_to_1 = random_affine(img2,
                                                       **affine_kwargs)  #
      # tensors
    else:
      affine2_to_1 = torch.zeros([2, 3]).to(torch.float32).cuda()  # identity
      affine2_to_1[0, 0] = 1
      affine2_to_1[1, 1] = 1

    # (img2) do random flip, tf_mat changes
    if np.random.rand() > self.flip_p:
      img2 = torch.flip(img2, dims=[2])  # horizontal, along width

      # applied affine, then flip, new = flip * affine * coord
      # (flip * affine)^-1 is just flip^-1 * affine^-1.
      # No order swap, unlike functions...
      # hence top row is negated
      affine2_to_1[0, :] *= -1.

    # uint8 tensor as masks should be binary, also for consistency,
    # but converted to float32 in main loop because is used
    # multiplicatively in loss
    mask_img1 = torch.ones(self.input_sz, self.input_sz).to(torch.uint8).cuda()

    if RENDER_DATA:
      render(img1, mode="image", name=("train_data_img1_%d" % index))
      render(img2, mode="image", name=("train_data_img2_%d" % index))
      render(affine2_to_1, mode="matrix",
             name=("train_data_affine2to1_%d" % index))
      render(mask_img1, mode="mask", name=("train_data_mask_%d" % index))

    return img1, img2, affine2_to_1, mask_img1

  def _prepare_train_single(self, index, img):
    # Returns one pair only, i.e. without transformed second image.
    # Used for standard CNN training (baselines).
    # This returns gpu tensors.
    # label is passed in canonical [0 ... 181] indexing

    img = img.astype(np.float32)

    # shrink original images, for memory purposes
    # or enlarge
    if self.pre_scale_all:
      img = cv2.resize(img, dsize=None, fx=self.pre_scale_factor,
                       fy=self.pre_scale_factor,
                       interpolation=cv2.INTER_LINEAR)

    # basic augmentation transforms for both img1 and img2
    if self.use_random_scale:
      # bilinear interp requires float img
      scale_factor = (np.random.rand() * (self.scale_max - self.scale_min)) + \
                     self.scale_min
      img = cv2.resize(img, dsize=None, fx=scale_factor, fy=scale_factor,
                       interpolation=cv2.INTER_LINEAR)

    # random crop to input sz
    img, coords = pad_and_or_crop(img, self.input_sz, mode="random")

    # converting to PIL does not change underlying np datatype it seems

    img1 = Image.fromarray(img.astype(np.uint8))

    img1 = self.jitter_tf(img1)  # not in place, new memory
    img1 = np.array(img1)

    # channels still last
    # channels still last
    if not self.no_sobel:
      img1 = custom_greyscale_numpy(img1, include_rgb=self.include_rgb)

    img1 = img1.astype(np.float32) / 255.

    # convert both to channel-first tensor format
    # make them all cuda tensors now, except label, for optimality
    img1 = torch.from_numpy(img1).permute(2, 0, 1).cuda()

    if self.use_random_affine:
      affine_kwargs = {"min_rot": self.aff_min_rot, "max_rot": self.aff_max_rot,
                       "min_shear": self.aff_min_shear,
                       "max_shear": self.aff_max_shear,
                       "min_scale": self.aff_min_scale,
                       "max_scale": self.aff_max_scale}
      img1, _, _ = random_affine(img1, **affine_kwargs)  # tensors

    # (img2) do random flip, tf_mat changes
    if np.random.rand() > self.flip_p:
      img1 = torch.flip(img1, dims=[2])  # horizontal, along width

    # uint8 tensor as masks should be binary, also for consistency,
    # but converted to float32 in main loop because is used
    # multiplicatively in loss
    mask_img1 = torch.ones(self.input_sz, self.input_sz).to(torch.uint8).cuda()

    if RENDER_DATA:
      render(img1, mode="image", name=("train_data_img1_%d" % index))
      render(mask_img1, mode="mask", name=("train_data_mask_%d" % index))
    print(img1.shape, mask_img1.shape)
    return img1, mask_img1

  def _prepare_test(self, index, img, label):
    # This returns cpu tensors.
    #   Image: 3D with channels last, float32, in range [0, 1] (normally done
    #     by ToTensor).
    #   Label map: 2D, flat int64, [0 ... self.gt_k - 1]
    # label is passed in canonical [0 ... 181] indexing

    assert (label is not None)

    assert (img.shape[:2] == label.shape)
    img = img.astype(np.float32)
    label = label.astype(np.int32)

    # shrink original images, for memory purposes, or magnify
    if self.pre_scale_all:
      img = cv2.resize(img, dsize=None, fx=self.pre_scale_factor,
                       fy=self.pre_scale_factor,
                       interpolation=cv2.INTER_LINEAR)
      label = cv2.resize(label, dsize=None, fx=self.pre_scale_factor,
                         fy=self.pre_scale_factor,
                         interpolation=cv2.INTER_NEAREST)

    # center crop to input sz
    img, _ = pad_and_or_crop(img, self.input_sz, mode="centre")
    label, _ = pad_and_or_crop(label, self.input_sz, mode="centre")

    # finish
    # may be concatenating onto just greyscale image
    if not self.no_sobel:
      img = custom_greyscale_numpy(img, include_rgb=self.include_rgb)

    img = img.astype(np.float32) / 255.

    img = torch.from_numpy(img).permute(2, 0, 1)

    if RENDER_DATA:
      render(label, mode="label", name=("test_data_label_pre_%d" % index))

    # convert to coarse if required, reindex to [0, gt_k -1], and get mask
    label = self._filter_label(label)
    mask = torch.ones(self.input_sz, self.input_sz).to(torch.uint8)

    if RENDER_DATA:
      render(img, mode="image", name=("test_data_img_%d" % index))
      render(label, mode="label", name=("test_data_label_post_%d" % index))
      render(mask, mode="mask", name=("test_data_mask_%d" % index))

    # dataloader must return tensors (conversion forced in their code anyway)
    return img, torch.from_numpy(label), mask

  def _preload_data(self):
    for image_id in tqdm(
      self.files, desc="Preloading...", leave=False, dynamic_ncols=True):
      image, label = self._load_data(image_id)
      self.images.append(image)
      self.labels.append(label)

  def __getitem__(self, index):
    if self.preload:
      image, label = self.images[index], self.labels[index]
    else:
      image_id = self.files[index]
      image, label = self._load_data(image_id)
    if self.purpose == "train":
      if not self.single_mode:
        return self._prepare_train(index, image)
      else:
        return self._prepare_train_single(index, image)
    else:
      assert (self.purpose == "test")
      return self._prepare_test(index, image, label)

  def __len__(self):
    return len(self.files)

  def _check_gt_k(self):
    raise NotImplementedError()

  def _filter_label(self, label):
    raise NotImplementedError()

  def _set_files(self):
    if self.split in ["unlabelled_train", "labelled_train", "labelled_test"]:
      if self.split.endswith('_train'):
        self.mode = 'training'
        file_list = os.listdir(osp.join(self.root, 'images', self.mode))
      else:
        self.mode = 'validation'
        file_list = os.listdir(osp.join(self.root, 'images', self.mode))
      self.files = file_list  # list of ids which may or may not have gt
    else:
      raise ValueError("Invalid split name: {}".format(self.split))

  def _load_data(self, image_id):
    image_path = osp.join(self.root, "images", self.mode, image_id)
    label_path = osp.join(self.root, "classes", self.mode, image_id.replace('RGB', 'CLS'))
    image = io.imread(image_path).astype(np.uint8)
    assert (image.dtype == np.uint8)

    if os.path.exists(label_path):
      label = io.imread(label_path).astype(np.int32)
      assert (label.dtype == np.int32)
      for key, value  in self.CLASS_DICT.items():
        label[label == key] = value
      return image, label
    else:
      return image, None

class DC(_DC):
  def __init__(self, **kwargs):
    super(DC, self).__init__(**kwargs)

    config = kwargs["config"]

  def _filter_label(self, label):
      return label

reason: import numpy,import scipy


text:
from .Scheduler import *
import numpy as np
from copy import deepcopy

class TMRScheduler(Scheduler):
    def __init__(self):
        super().__init__()

    def selection(self):
        selectedHostIDs = self.ThresholdHostSelection()
        selectedIDs = self.MaxUseContainerSelection(selectedHostIDs)
        return selectedIDs

    def placement(self, containerIDs):
        return self.RandomPlacement(containerIDs)

max_issues_repo_name: imperial-qore/CAROL

max_forks_repo_name: imperial-qore/CAROL


text:
import numpy as np
from sklearn import preprocessing, cross_validation, neighbors
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns

from sklearn import metrics
from sklearn import preprocessing, cross_validation, neighbors, svm
from sklearn.preprocessing import StandardScaler

n_components=2
t_size=0.2

df = pd.read_csv('phising data with description.txt')
#print("Full data: ")
#print(df)

#print("df size before drop: ")
#print(df.shape)
#print("Column 1: ")
#print(df['c1'])

#print("Result data: ")
#print(df['result'])

X=np.array(df.drop(['result'],1))
#print("X: ")
#print(X)
y=np.array(df['result'])
#print("y: ")
#print(y)
#print(y.shape)
#print(X.shape)

#print("df size after drop: ")
#print(df.shape)

true=1
while true:

    X_train,X_test,y_train,y_test=cross_validation.train_test_split(X,y,test_size=t_size)
    clf=neighbors.KNeighborsClassifier()
    clf.fit(X_train,y_train)

    #find the accuracy for Original phishing
    accuracy_original = clf.score(X_test,y_test)
    print("Accuracy for Original Phishing KNN: ")
    print(accuracy_original)

    #find null accuracy for original dataset

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for original dataset: ",count.head(1)[1]/2211)
    print("Accuracy for original by confusion matrix: ",acc)
    print("Error rate for original KNN: ",err)
    print("Sensitivity  for original KNN: ",sen)
    print("Specificity  for original KNN: ",spe)
    print("Precision  for original KNN: ",pre)
    print("Recall  for original KNN: ",rec)
    print("F-Score  for original KNN: ",fsc)
    print("TPR  for original KNN: ",tpr)
    print("FPR  for original KNN: ",fpr)
    print()

#original SVM

    clf_svm=svm.SVC()
    clf_svm.fit(X_train,y_train)
    #find the accuracy for SVM
    accuracy_pca_svm = clf_svm.score(X_test,y_test)
    print("Accuracy for Original svm: ")
    print(accuracy_pca_svm)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_svm.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for original dataset : ",count.head(1)[1]/2211)
    print("Accuracy for original SVM: ",acc)
    print("Error rate for original SVM: ",err)
    print("Sensitivity  for original SVM: ",sen)
    print("Specificity  for original SVM: ",spe)
    print("Precision  for original SVM: ",pre)
    print("Recall  for original SVM: ",rec)
    print("F-Score  for original SVM: ",fsc)
    print("TPR  for original SVM: ",tpr)
    print("FPR  for original SVM: ",fpr)
    print()

    #original + Random Forest
    from sklearn.ensemble import RandomForestClassifier

    clf_rf=RandomForestClassifier(n_estimators=100)
    clf_rf.fit(X_train,y_train)
    #find the accuracy for SVM
    accuracy_pca_rf = clf_rf.score(X_test,y_test)
    print("Accuracy for Original & RF: ")
    print(accuracy_pca_rf)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_rf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for pca dataset : ",count.head(1)[1]/2211)
    print("Accuracy for original RF: ",acc)
    print("Error rate for original RF: ",err)
    print("Sensitivity  for original RF: ",sen)
    print("Specificity  for original RF: ",spe)
    print("Precision  for original RF: ",pre)
    print("Recall  for original RF: ",rec)
    print("F-Score  for original RF: ",fsc)
    print("TPR  for original RF: ",tpr)
    print("FPR  for original RF: ",fpr)
    print()

    #PCA

    scaler = StandardScaler()
    scaler.fit(df.drop(['result'],1))
    scaled_data = scaler.transform(df.drop(['result'],1))

    from sklearn.decomposition import PCA
    pca = PCA(n_components)

    # fragmenting in components, final result is x_pca
    pca.fit(scaled_data)
    x_pca = pca.transform(scaled_data)
    print("Size of data for original and after pca")
    print(scaled_data.shape)
    print(x_pca.shape)

    #print("data after PCA: ")
    #print(x_pca)

    #plot the orthoganal components in X Y axis

    plt.figure(figsize=(10,10))
    plt.scatter(x_pca[:,0],x_pca[:,1],c=y,cmap='plasma')
    plt.xlabel('First Component')
    plt.ylabel('Second Component')
    #plt.zlabel('Third Component')

    #plt.show()

    #fit to KNN
    X=x_pca
    #print("X for knn: ")
    #print(X)

    y=np.array(y)
    #print ("y for knn: ")
    #print(y)
    #print("changed data:")
    #print(type(x_pca))
    #print(type(y))

    # import necessary things for KNN and accuracy

    #print("Test")

    X_train,X_test,y_train,y_test=cross_validation.train_test_split(X,y,test_size=t_size)
    clf=neighbors.KNeighborsClassifier()
    clf.fit(X_train,y_train)

    #find the accuracy for KNN
    accuracy_pca = clf.score(X_test,y_test)
    print("Accuracy for PCA KNN: ")
    print(accuracy_pca)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for pca dataset: ",count.head(1)[1]/2211)
    print("Accuracy for pca by confusion matrix: ",acc)
    print("Error rate for pca KNN: ",err)
    print("Sensitivity  for pca KNN: ",sen)
    print("Specificity  for pca KNN: ",spe)
    print("Precision  for pca KNN: ",pre)
    print("Recall  for pca KNN: ",rec)
    print("F-Score  for pca KNN: ",fsc)
    print("TPR  for pca KNN: ",tpr)
    print("FPR  for pca KNN: ",fpr)
    print()

    #PCA + SVM

    clf_svm=svm.SVC()
    clf_svm.fit(X_train,y_train)
    #find the accuracy for SVM
    accuracy_pca_svm = clf_svm.score(X_test,y_test)
    print("Accuracy for PCA svm: ")
    print(accuracy_pca_svm)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_svm.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for pca dataset : ",count.head(1)[1]/2211)
    print("Accuracy for pca SVM: ",acc)
    print("Error rate for pca SVM: ",err)
    print("Sensitivity  for pca SVM: ",sen)
    print("Specificity  for pca SVM: ",spe)
    print("Precision  for pca SVM: ",pre)
    print("Recall  for pca SVM: ",rec)
    print("F-Score  for pca SVM: ",fsc)
    print("TPR  for pca SVM: ",tpr)
    print("FPR  for pca SVM: ",fpr)
    print()

    #PCA + Random Forest
    from sklearn.ensemble import RandomForestClassifier

    clf_rf=RandomForestClassifier(n_estimators=100)
    clf_rf.fit(X_train,y_train)
    #find the accuracy for SVM
    accuracy_pca_rf = clf_rf.score(X_test,y_test)
    print("Accuracy for PCA & RF: ")
    print(accuracy_pca_rf)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_rf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for pca dataset : ",count.head(1)[1]/2211)
    print("Accuracy for pca RF: ",acc)
    print("Error rate for pca RF: ",err)
    print("Sensitivity  for pca RF: ",sen)
    print("Specificity  for pca RF: ",spe)
    print("Precision  for pca RF: ",pre)
    print("Recall  for pca RF: ",rec)
    print("F-Score  for pca RF: ",fsc)
    print("TPR  for pca RF: ",tpr)
    print("FPR  for pca RF: ",fpr)
    print()

    #PCA + Linear regression
    from sklearn import linear_model
    print("n_components: ",n_components)
    linear_regression = linear_model.LinearRegression()
    linear_regression.fit(X_train,y_train)
    #find the accuracy for linear regression
    accuracy_pca_lr = linear_regression.score(X_test,y_test)
    print("Accuracy for PCA & LR: ")
    print(accuracy_pca_lr)

    #PCA + Logistic regression
    from sklearn.linear_model import LogisticRegression
    model = LogisticRegression(penalty='l2',C=1)
    model.fit(X_train,y_train)

    #find the accuracy for Logistic regression
    accuracy_pca_logr = model.score(X_test,y_test)
    print("Accuracy for PCA & Logistic R: ")
    print(accuracy_pca_logr)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=model.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for pca dataset : ",count.head(1)[1]/2211)
    print("Accuracy for pca LogR: ",acc)
    print("Error rate for pca LogR: ",err)
    print("Sensitivity  for pca LogR: ",sen)
    print("Specificity  for pca LogR: ",spe)
    print("Precision  for pca LogR: ",pre)
    print("Recall  for pca LogR: ",rec)
    print("F-Score  for pca LogR: ",fsc)
    print("TPR  for pca LogR: ",tpr)
    print("FPR  for pca LogR: ",fpr)
    print()

    #Random Gaussian Projection

    from sklearn import random_projection

    transformer = random_projection.GaussianRandomProjection(n_components)
    print("Transformer matrix: ")
    print(transformer)
    X = transformer.fit_transform(df.drop(['result'],1))
    y=np.array(df['result'])

    #find accuracy for random gaussian Projection
    X_train,X_test,y_train,y_test=cross_validation.train_test_split(X,y,test_size=t_size)
    clf=neighbors.KNeighborsClassifier()
    clf.fit(X_train,y_train)

    #find the accuracy for RGP
    accuracy_gaussian = clf.score(X_test,y_test)
    print("Accuracy for gaussian KNN: ")
    print(accuracy_gaussian)

    #Gaussian KNN
    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for original dataset: ",count.head(1)[1]/2211)
    print("Accuracy for Gaussian by confusion matrix: ",acc)
    print("Error rate for Gaussian KNN: ",err)
    print("Sensitivity  for Gaussian KNN: ",sen)
    print("Specificity  for Gaussian KNN: ",spe)
    print("Precision  for Gaussian KNN: ",pre)
    print("Recall  for Gaussian KNN: ",rec)
    print("F-Score  for Gaussian KNN: ",fsc)
    print("TPR  for Gaussian KNN: ",tpr)
    print("FPR  for Gaussian KNN: ",fpr)
    print()

    #Gaussian SVM

    clf_svm=svm.SVC()
    clf_svm.fit(X_train,y_train)
    #find the accuracy for SVM
    accuracy_gau_svm = clf_svm.score(X_test,y_test)
    print("Accuracy for Gaussian svm: ")
    print(accuracy_gau_svm)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_svm.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for Gaussian dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for pca dataset : ",count.head(1)[1]/2211)
    print("Accuracy for Gaussian SVM: ",acc)
    print("Error rate for Gaussian SVM: ",err)
    print("Sensitivity  for Gaussian SVM: ",sen)
    print("Specificity  for Gaussian SVM: ",spe)
    print("Precision  for Gaussian SVM: ",pre)
    print("Recall  for Gaussian SVM: ",rec)
    print("F-Score  for Gaussian SVM: ",fsc)
    print("TPR  for Gaussian SVM: ",tpr)
    print("FPR  for Gaussian SVM: ",fpr)
    print()

    #Gausian + RF

    clf_rf=RandomForestClassifier(n_estimators=100)
    clf_rf.fit(X_train,y_train)
    #find the accuracy for Gaussian RF
    accuracy_Gau_rf = clf_rf.score(X_test,y_test)
    print("Accuracy for Gausian & RF: ")
    print(accuracy_Gau_rf)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_rf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for Original dataset : ",count.head(1)[1]/2211)
    print("Accuracy for Gausian RF: ",acc)
    print("Error rate for Gausian RF: ",err)
    print("Sensitivity  for Gausian RF: ",sen)
    print("Specificity  for Gausian RF: ",spe)
    print("Precision  for Gausian RF: ",pre)
    print("Recall  for Gausian RF: ",rec)
    print("F-Score  for Gausian RF: ",fsc)
    print("TPR  for pca Gausian: ",tpr)
    print("FPR  for pca Gausian: ",fpr)
    print()

    #Random Sparse Projection

    transformer = random_projection.SparseRandomProjection(n_components)
    X = transformer.fit_transform(df.drop(['result'],1))

    y=df['result']

    #find accuracy for random Sparse Projection
    X_train,X_test,y_train,y_test=cross_validation.train_test_split(X,y,test_size=t_size)
    clf=neighbors.KNeighborsClassifier()
    clf.fit(X_train,y_train)

    #find the accuracy for RSP and KNN
    accuracy_sparse = clf.score(X_test,y_test)
    print("Accuracy for Sparse Projection KNN: ")
    print(accuracy_sparse)

    #Sparse KNN
    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for original dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for original dataset: ",count.head(1)[1]/2211)
    print("Accuracy for Sparse by confusion matrix: ",acc)
    print("Error rate for Sparse KNN: ",err)
    print("Sensitivity  for Sparse KNN: ",sen)
    print("Specificity  for Sparse KNN: ",spe)
    print("Precision  for Sparse KNN: ",pre)
    print("Recall  for Sparse KNN: ",rec)
    print("F-Score  for Sparse KNN: ",fsc)
    print("TPR  for Sparse KNN: ",tpr)
    print("FPR  for Sparse KNN: ",fpr)
    print()

    clf_svm=svm.SVC()
    clf_svm.fit(X_train,y_train)

    #find the accuracy for RSP SVM

    accuracy_spa_svm = clf_svm.score(X_test,y_test)
    print("Accuracy for Sparse svm: ")
    print(accuracy_spa_svm)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_svm.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for Sparse dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for Original dataset : ",count.head(1)[1]/2211)
    print("Accuracy for Sparse SVM: ",acc)
    print("Error rate for Sparse SVM: ",err)
    print("Sensitivity  for Sparse SVM: ",sen)
    print("Specificity  for Sparse SVM: ",spe)
    print("Precision  for Sparse SVM: ",pre)
    print("Recall  for Sparse SVM: ",rec)
    print("F-Score  for Sparse SVM: ",fsc)
    print("TPR  for Sparse SVM: ",tpr)
    print("FPR  for Sparse SVM: ",fpr)
    print()

    #Sparse and RF

    clf_rf=RandomForestClassifier(n_estimators=100)
    clf_rf.fit(X_train,y_train)
    #find the accuracy for Gaussian RF
    accuracy_spa_rf = clf_rf.score(X_test,y_test)
    print("Accuracy for Sparse & RF: ")
    print(accuracy_spa_rf)

    yt=pd.Series(y_test)
    #print(yt.value_counts())
    count=yt.value_counts()
    #print(max(yt.mean(),1-yt.mean()))
    #print(count.head(1)[1]/2211)

    y_predict=clf_rf.predict(X_test)

    conf=metrics.confusion_matrix(y_test,y_predict)
    print("Confusion matrix for Sparse dataset: ")
    print(conf)

    TP=conf[1,1]
    TN=conf[0,0]
    FP=conf[0,1]
    FN=conf[1,0]

    acc=(TP+TN)/(TP+TN+FP+FN)
    err=(1-acc)
    sen=TP/(TP+FN)
    spe=TN/(FP+TN)
    pre=TP/(TP+FP)
    rec=TP/(TP+FN)
    fsc=(2*pre*rec)/(pre+rec)
    tpr=sen
    fpr=(1-spe)

    print()
    print("n_components: ",n_components)
    print("test size: ",t_size)
    print("null accuracy for Original dataset : ",count.head(1)[1]/2211)
    print("Accuracy for Sparse RF: ",acc)
    print("Error rate for Sparse RF: ",err)
    print("Sensitivity  for Sparse RF: ",sen)
    print("Specificity  for Sparse RF: ",spe)
    print("Precision  for Sparse RF: ",pre)
    print("Recall  for Sparse RF: ",rec)
    print("F-Score  for Sparse RF: ",fsc)
    print("TPR  for pca Sparse: ",tpr)
    print("FPR  for pca Sparse: ",fpr)
    print()

    #print("test size: ",t_size)
    #t_size = t_size + 0.05

    #if t_size > 0.5:
    #    break
    n_components=n_components+1
    if n_components > 10:
        break

    print()
    print()
    print()

    print("feature : ",n_components)
    print("Original: ",accuracy_original)
    print("PCA     : ",accuracy_pca)
    print("Sparse  : ",accuracy_sparse)
    print("Gaussian: ",accuracy_gaussian)

    print()
    print("pca & knn: ",accuracy_pca)
    print("pca & svm: ",accuracy_pca_svm)
    print("pca & rf: ",accuracy_pca_rf)
    print("pca & lr: ",accuracy_pca_lr)
    print("pca & logR: ",accuracy_pca_logr)


text:
"""An environment wrapper to clip rewards."""
import gym
import numpy as np

class ClipRewardEnv(gym.RewardWrapper):
    """An environment that clips rewards in {-1, 0, 1}."""

    def reward(self, reward: float) -> float:
        """Bin reward to {-1, 0, +1} using its sign."""
        return np.sign(reward)

# explicitly specify the external API of this module
__all__ = [ClipRewardEnv.__name__]

max_stars_repo_name: Olloxan/gym-tetris

max_issues_repo_name: Olloxan/gym-tetris

max_forks_repo_name: Olloxan/gym-tetris


text:
import numpy as np
from pathlib import Path

class Panel:

    def __init__(self, filepath):
        # Importing in the file path (have to add a . because it is in /~/src instead of /~
        self.filepath = '.' +  filepath

        """ I/O the 136 HIV panel fasta sequence """
        base_path = Path(__file__).parent
        file_path = (base_path / self.filepath).resolve()
        # (x, y), where x is the sequence index and panel_dict[x] is the actual amino acid sequence
        panel_dict = {}
        # Bootstrapped coordinate compression for panel_dict sequence name and its corresponding sequence index
        # panel_compression[sequence name] == sequence index
        panel_compression = {}
        # Opposite/reverse of panel_compression, opp[seq index] == seq name
        opposite_panel_compression = {}

        """ Inputting and reading the file """
        panel_compression_counter = 0
        with open(file_path, 'r') as f:
            prev = ''
            for x, line in enumerate(f):
                if (x % 2 == 0):
                    prev = line[1:]
                else:
                    panel_dict[panel_compression_counter] = line
                    prev = prev.split('\n')[0] # IO adds an extra \n to the end of the prev name
                    # print('prev:', prev, 'panel_compression_counter:', panel_compression_counter)
                    panel_compression[prev] = panel_compression_counter
                    opposite_panel_compression[panel_compression_counter] = prev
                    panel_compression_counter += 1
        sequence_length = len(panel_dict[0])
        self.sequence_length = sequence_length
        self.panel_compression_counter = panel_compression_counter

        f.close()

        """
        # Printing out the panel_dict
        for x in panel_dict:
            print('Strand Number: ', x, ' Sequence: ', panel_dict[x])
        """

        """
        Determining the consensus sequence in O(n * k)
        where n is the number of characters in a sequence, and k is the number of sequences
        """
        consensus_sequence = ''
        for x in range(sequence_length - 1):
            letter_counter = np.zeros((27), dtype=int)
            for y in panel_dict:
                if (panel_dict[y][x] != '-'):
                    letter_counter[ord(panel_dict[y][x]) - 65] += 1
                else:
                     letter_counter[26] += 1
            # best_letter[0][0] gives the first index of the indices that have the highest value
            # best_letter[0] gives all the indices where that element's value is the same as the max
            # For example, if array is [1, 5, 5], best_letter[0][0] gives 1, whereas best_letter[0] gives [1 2]
            best_letter = np.where(letter_counter == np.amax(letter_counter))
            if (best_letter[0][0] != 26):
                consensus_sequence += chr(best_letter[0][0] + 65)
            else:
                consensus_sequence += '-'

        """ Making everything a self so that other methods can access the variables  """
        self.consensus_sequence = consensus_sequence
        # (x, y), where x is the sequence index and panel_dict[x] is the actual amino acid sequence
        self.panel_dict = panel_dict
        # panel_compression[sequence name] == sequence index
        self.panel_compression = panel_compression

    """ Returning the consensus sequence  """
    def get_consensus_sequence(self):
        return self.consensus_sequence

    """ Get a HIV sequence from the panel  """
    def get_seq_from_name(self, seq_header):
        return self.panel_dict[self.panel_compression[seq_header]]

    """ Get a HIV sequence from the panel  """
    def get_seq(self, seq_index):
        return self.panel_dict[seq_index]

    """ Getting the length of each sequence """
    def get_seq_length(self):
        return self.sequence_length

    def get_number_of_seq(self):
        return self.panel_compression_counter

max_stars_repo_path: Week 3/src/panel.py

max_issues_repo_path: Week 3/src/panel.py

max_forks_repo_path: Week 3/src/panel.py


text:
#!/usr/bin/python3
# ‑∗‑ coding: utf‑8 ‑∗‑

import sys
import monitor
import numpy as np

from collections import deque

class Bench:
    """ Initialize the bench class.

    Args:
        env: instance of OpenAI Gym's environment
        agent: agent that will interact with the environment.
        nb_bench: number of episodes of agent-environment interaction
        nb_episodes: number of episodes of agent-environment interaction
        window: number of episodes to consider when calculating average rewards.

    Attributes:
        env: instance of OpenAI Gym's environment
        agent: agent that will interact with the environment.
        nb_episodes: number of episodes of agent-environment interaction
        window: number of episodes to consider when calculating average rewards.
    """
    def __init__(self, env, agent_class, agent_parameters=None, nb_bench=10, nb_episodes=20000, window=100):
        self.env = env
        self.agent_class = agent_class
        self.agent_parameters = agent_parameters
        self.nb_bench = nb_bench
        self.nb_episodes = nb_episodes
        self.window = window

        self.results = {
            "best_average_reward": np.NINF,
            "average_rewards": [],
        }

    def init_agent(self):
        if self.agent_parameters:
            return self.agent_class(self.env.action_space.n, **self.agent_parameters)
        else:
            return self.agent_class(self.env.action_space.n)

    def run_bench(self):
        results_list = []

        print("Bench: {}/{}".format(1, self.nb_bench))

        agent = self.init_agent()
        monitor_env = monitor.Monitor(self.env, agent, nb_episodes=self.nb_episodes)

        results = monitor_env.interact()

        for i_bench in range(2, self.nb_bench+1):
            print("Bench: {}/{}".format(i_bench, self.nb_bench))

            agent = self.init_agent()
            monitor_env = monitor.Monitor(self.env, agent, nb_episodes=self.nb_episodes, window=self.window)

            tmp_results = monitor_env.interact()

            results["best_average_reward"] += (1/i_bench) * (tmp_results["best_average_reward"] - results["best_average_reward"])
            results["average_rewards"] += (1/i_bench) * (tmp_results["average_rewards"] - results["average_rewards"])

        results["average_rewards"] = np.round(results["average_rewards"], 3)
        results["average_rewards"] = list(results["average_rewards"])

        return results

max_stars_repo_name: Lucien-MG/rl-blackjack

max_issues_repo_name: Lucien-MG/rl-blackjack

max_forks_repo_name: Lucien-MG/rl-blackjack


text:
import cv2
import numpy as np
import numpad
import math

def add_image_horizontal(image, image_to_add):
  return np.vstack((image, image_to_add))

def add_image_vertical(image, image_to_add):
  return np.hstack((image, image_to_add))

def detect_clicked_button_show_click(all_image, shared, visualize_button=True, visualize_text=True):
  """
  ! require shared.landmarks, shared.width, shared.height !
  ! shared.numpad_buttons_3dpos_and_type shared.dynamic_button_size shared.thumb_range!
  ! shared.is_open shared.clicked_pos_3d  shared.clicked_button!
  Calculates the euclidean_distance between thumb 3d pos with landmarks to see
  if a button is pressed.

  The visualize the result.

  Result saved in:
  shared.clicked_button
  shared.clicked_pos_3d
  """

  if ( shared.landmarks is not None):

    thumb = VectorMessageObj_To3dVec(shared.landmarks[0]["landmark"][4], shared.width, shared.height)

    current_distance = math.inf
    current_name = ""
    current_pos = None

    font                   = cv2.FONT_HERSHEY_SIMPLEX
    fontScale              = 1
    fontColor              = (255,255,255)
    lineType               = 2

    for [v,name] in shared.numpad_buttons_3dpos_and_type:

      tmp = euclidean_distance(thumb, v)
      if tmp < shared.dynamic_button_size*shared.thumb_range and tmp < current_distance: # change this to make buttons easier to press
        current_name = name
        current_pos = v

    shared.clicked_pos_3d = current_pos
    shared.clicked_button = current_name

    # Show text at bottom!
    if visualize_text:
      if shared.is_open:
        cv2.putText(all_image,
        "Pressed button: "+current_name,
          (50,int(shared.height-50)),
          font,
          fontScale,
          fontColor,
          lineType)

      if visualize_button and current_pos is not None:
        all_image = cv2.circle(all_image, (current_pos[0],current_pos[1]), shared.dynamic_button_size,(0,255,0), 4)
  return all_image

def show_hand_and_score(all_image, shared):
  """
  ! require shared.handedness shared.box !
  Show default classification result from mediapipe
  In upper corner of box!
  """
  if ( shared.handedness is not None):
    font                   = cv2.FONT_HERSHEY_SIMPLEX
    fontScale              = 1
    fontColor              = (255,255,255)
    lineType               = 2
    cv2.putText(all_image,
    str(shared.handedness["classification"][0]["label"])+" "+ str(round(shared.handedness["classification"][0]["score"],3)),
      (shared.box[0],shared.box[1]),
      font,
        fontScale,
        fontColor,
          lineType)
  return all_image

def calculate_and_show_numpad( all_image, shared, show_thumb_range = False, hide_if_open=False, min_hand_size_limit=0):
  """
  ! Require if hide_if_open == true: shared.is_open, shared.size !
  This is a help function to sort result depending on if you want to show debug or result mode.
  hide_if_open set the mode!
  """
  if(hide_if_open):
    if shared.is_open and shared.size[0]*shared.size[1] > min_hand_size_limit:

      return calculate_and_show_numpad_func(all_image, shared, show_thumb_range)
    else:
      return all_image
  else:
    return calculate_and_show_numpad_func(all_image, shared, show_thumb_range)

def calculate_and_show_numpad_func(all_image, shared, show_thumb_range):
  """
  Executed function of the above
   ! Requires: shared.landmarks, shared.handedness, shared.leftNumpadEnum, !
   ! shared.thumb_range,  shared.rightNumpadEnum, !
   ! shared.dynamic_button_size !
   ! shared.size, shared.width, shared.height !
   ! shared.numpad_buttons_3dpos_and_type !
  Calculate and place numpad numbers with circles
  Depending on which hand is used. Mirror positions using numpad.Enums.
  Basicly the end result visualisation function!
  """

  shared.numpad_buttons_3dpos_and_type = []

  if shared.handedness is not None:
    # Right or Left hand?

    enum_type = None
    font                   = cv2.FONT_HERSHEY_SIMPLEX
    fontScale              = 1
    fontColor = (255,255,255)
    color = (0,0,255)
    lineType               = 2
    enum_arr = []

    if(shared.handedness["classification"][0]["label"] == "left"):
      enum_arr = shared.leftNumpadEnum
      enum_type = numpad.LeftNumpadPoints
    else:
      enum_arr = shared.rightNumpadEnum
      enum_type = numpad.RightNumpadPoints

    for index in enum_arr:
      #print(enum_type(index).value[0], len(shared.landmarks[0]["landmark"]))
      enum_name =  enum_type(index)
      #print(str(enum_name))
      number_name = str(enum_name).split(".")[1].replace("Key","")

       # Clamp size of circle
      dynamic_size = int(max(shared.size)/35)
      if dynamic_size <= 0:
        dynamic_size = 1

      pos = shared.filtered_landmarks[int(enum_type(index).value[0])]
      tmp =(int(pos[0]), int(pos[1]))

      if (number_name == "Thumb"):
        color = (0,255,255)
        if show_thumb_range:
          all_image = cv2.circle(all_image, tmp, dynamic_size*shared.thumb_range,color, 2)
        color = (255,255,0)
      else:
        shared.numpad_buttons_3dpos_and_type.append([np.array([int(pos[0]), int(pos[1]), int(pos[2])]), number_name])

      pos = tmp
      """
      #print(enum_type(index),"at", pos)
      #print("circle dynamic size", )
      """
      shared.dynamic_button_size = dynamic_size

      all_image = cv2.circle(all_image, pos, dynamic_size,color, 2)

      # Show correct number
      cv2.putText(all_image, number_name,  (pos[0]-dynamic_size,pos[1]+dynamic_size), font, fontScale, fontColor, lineType)
  return all_image

def calculate_and_draw_center_of_hand(all_image, shared, visualize_point=True):
  """
  ! Require shared.landmarks, shared.width, shared.height !
  Calculate median of all landmarks
  Calculate kalman on midpoint
  Redistribute landmarks depending on kalman result
  Print resulting middle point

  Save result at:
  shared.midpoint
  shared.filtered_landmarks

  Note: several good prints saved in this code!
  """
  if shared.landmarks is not None:
    all_x_landmarks = []
    all_y_landmarks = []
    all_z_landmarks = []
    for landmark in shared.landmarks[0]["landmark"]:
      all_x_landmarks.append(landmark["x"])
      all_y_landmarks.append(landmark["y"])
      all_z_landmarks.append(landmark["z"])

    median_x = int(np.median(all_x_landmarks)* shared.width)
    median_y = int(np.median(all_y_landmarks)* shared.height)
    median_z = int(np.median(all_z_landmarks)* shared.height)

    radius = 2
    color = (255, 0, 0)
    thickness = 8

    """
    #before = []
    #for i in range(0,len(all_x_landmarks)):
    #  before.append([all_x_landmarks[i]* shared.width, all_y_landmarks[i]* shared.height, all_z_landmarks[i]* shared.height])
    """

    # Filter all landmarks
    diff_array= []
    for i in range(0,len(all_x_landmarks)):
      diff_array.append([all_x_landmarks[i]* shared.width-median_x, all_y_landmarks[i]* shared.height-median_y, all_z_landmarks[i]* shared.height-median_z])

    filtered = shared.kalman_filter.filter_pos(median_x, median_y)

    shared.midpoint = [filtered[0], filtered[1], median_z]

    # Place landmarks correct
    filtered_landmarks = []
    for i in range(0,len(all_x_landmarks)):
      filtered_landmarks.append([diff_array[i][0]+shared.midpoint[0],diff_array[i][1]+shared.midpoint[1], diff_array[i][2]+shared.midpoint[2]])

    """
    #print("before",before)
    #print("after",filtered_landmarks)
    """

    shared.filtered_landmarks = filtered_landmarks
    if visualize_point:
      all_image = cv2.circle(all_image, (median_x, median_y), radius, color, thickness)

  return all_image

def calculate_hand_size_and_draw_boxes(all_image, shared, visualize_boxes=True):
  """
   ! Require shared.landmarks, shared.width, shared.height !
  Calculate max and min distance between landmarks to median center.
  Then multiply it by 2.
  Store result as:
  shared.size = (x,y)
  shared.box = [xmin, ymin, xmax,ymax]
  """

  if shared.landmarks is not None:
    all_x_landmarks = []
    all_y_landmarks = []
    for landmark in shared.landmarks[0]["landmark"]:
      all_x_landmarks.append(landmark["x"])
      all_y_landmarks.append(landmark["y"])

    minx = min(all_x_landmarks)
    maxx = max(all_x_landmarks)
    miny = min(all_y_landmarks)
    maxy = max(all_y_landmarks)

    x_diff = (maxx - minx)/2
    y_diff = (maxy - miny)/2

    start_box = (int((minx-x_diff)*shared.width), int((miny-y_diff)*shared.height))
    end_box = (int((maxx+x_diff)*shared.width), int((maxy+y_diff)*shared.height))

    shared.size=(end_box[0]-start_box[0], end_box[1]-start_box[1])
    shared.box = [start_box[0], start_box[1], end_box[0], end_box[1]]

    if visualize_boxes:
      color = (0, 0, 255)
      thickness = 2

      all_image = cv2.rectangle(all_image, start_box, end_box, color, thickness)
  return all_image

def calculate_and_show_direction(all_image, shared, visualize_vectors=True):
  """
  ! Require shared.landmarks, shared.direction_scale, shared.width, shared.height !
  With simple Linear algebra we use 3 points on the hand to create a plane.
  Then calculate and print Normal Base Vectors (x,y,(z = n) for plane) of length "shared.direction_scale" see below
  Save result as shared.rotmatrix
  """

  if shared.landmarks is not None:

    m0 =shared.landmarks[0]["landmark"][0]
    m1 = shared.landmarks[0]["landmark"][5]
    m2 = shared.landmarks[0]["landmark"][17]

    p2 =  np.array([m2["x"],m2["y"],m2["z"]])
    p1 =  np.array([m1["x"],m1["y"],m1["z"]])
    p0 = np.array([m0["x"],m0["y"],m0["z"]])

    n0 = p0-p1
    n1 = p2- (np.dot(p2, n0)/np.sqrt(sum(n0**2))**2)*n0 # Linear Projection!
    n2 = np.cross(n0,n1)

    f0 = n0/np.linalg.norm(n0)
    f1 = n1/np.linalg.norm(n1)
    f2 = n2/np.linalg.norm(n2)

    #print("is ortogonal ", round(np.dot(f0, f1)), round(np.dot(f0, f2),4), round(np.dot(f1, f2),4))

    font                   = cv2.FONT_HERSHEY_SIMPLEX
    fontScale              = 1
    fontColor              = (255,255,255)
    lineType               = 2

    origo = (int(p0[0]*shared.width), int(p0[1]*shared.height))
    xaxis = (int(p0[0]*shared.width-f0[0]*shared.direction_scale), int(p0[1]*shared.height-f0[1]*shared.direction_scale))
    yaxis = (int(p0[0]*shared.width+f1[0]*shared.direction_scale), int(p0[1]*shared.height+f1[1]*shared.direction_scale))
    zaxis = (int(p0[0]*shared.width+f2[0]*shared.direction_scale), int(p0[1]*shared.height+f2[1]*shared.direction_scale))

    shared.rotmatrix = np.array([f0,f1,f2])

    if visualize_vectors:
      cv2.putText(all_image, "x",  xaxis, font, fontScale, fontColor, lineType)
      all_image = cv2.line(all_image, origo, xaxis , (255,0,0), 6)
      cv2.putText(all_image, "y", yaxis, font, fontScale, fontColor, lineType)
      all_image = cv2.line(all_image,origo ,yaxis, (0,255,0), 6)
      cv2.putText(all_image, "z", zaxis, font, fontScale, fontColor, lineType)
      all_image = cv2.line(all_image, origo, zaxis, (0,0,255), 6)

  return all_image

def VectorMessageObj_To2dVec(messageObj, width=1, height=1):
  return np.array([int(messageObj["x"]*width),int(messageObj["y"]*height)])

def VectorMessageObj_To3dVec(messageObj, width=1, height=1):
  return np.array([int(messageObj["x"]*width),int(messageObj["y"]*height), int(messageObj["z"]*height)])

def euclidean_distance(v1,v2): # np vectors!
  return np.linalg.norm(v1-v2)

def calculate_show_is_open(all_image,shared, visualize_text=True, visualize_detection=True):
  """
  ! Require shared.landmarks, shared.size, shared.width, shared.height !
  Calculates if hand is open
  Uses endpoints of fingers to see if they intersect the wrist point
  Using euclidean_distance.
  Save result as shared.is_open
  """
  # if landmark 8,12,16,20 is close to 0
  if shared.landmarks is not None:

    too_close_limit = int(max(shared.size)/3)
    _open = True

    intresting_landmarks = [
      VectorMessageObj_To3dVec(shared.landmarks[0]["landmark"][8], shared.width, shared.height),
      VectorMessageObj_To3dVec(shared.landmarks[0]["landmark"][12], shared.width, shared.height),
      VectorMessageObj_To3dVec(shared.landmarks[0]["landmark"][16], shared.width, shared.height),
      VectorMessageObj_To3dVec(shared.landmarks[0]["landmark"][20], shared.width, shared.height)
    ]

    font                   = cv2.FONT_HERSHEY_SIMPLEX
    fontScale              = 1
    fontColor              = (255,255,255)
    lineType               = 2
    wrist = VectorMessageObj_To3dVec(shared.landmarks[0]["landmark"][0], shared.width, shared.height)

    res = []
    for landmark in intresting_landmarks:
      tmp = euclidean_distance(wrist, landmark)
      res.append(tmp)
      if tmp < too_close_limit:
        _open = False

    shared.is_open = _open
    # show text
    if visualize_text:
      cv2.putText(all_image,
      "Open: "+str(_open),
        (shared.box[0],shared.box[3]),
        font,
          fontScale,
          fontColor,
            lineType)

    if visualize_detection:
      # show lines!
      origo = VectorMessageObj_To2dVec(shared.landmarks[0]["landmark"][0], shared.width, shared.height)

      # show close limit
      cv2.circle(all_image, (origo[0],origo[1]), too_close_limit, (255,0,0), 2)

      for i in range(0,len(res)):
        color = (0,0,255)
        if res[i]< too_close_limit:
          color = (0,255,0)
        all_image = cv2.line(all_image, (origo[0],origo[1]), (intresting_landmarks[i][0], intresting_landmarks[i][1]) , color, 1)

  return all_image

max_stars_repo_name: grebtsew/ARNumpad

max_issues_repo_name: grebtsew/ARNumpad

max_forks_repo_name: grebtsew/ARNumpad


text:
"""
Credits : https://medium.com/@kennethjiang/calibrate-fisheye-lens-using-opencv-333b05afa0b0
"""

import cv2
# assert cv2.__version__[0] == '3', 'The fisheye module requires opencv version >= 3.0.0'

import numpy as np
import os
import glob
import pickle

CHECKERBOARD = (6,9)

subpix_criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
calibration_flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC + cv2.fisheye.CALIB_CHECK_COND + cv2.fisheye.CALIB_FIX_SKEW

objp = np.zeros((1, CHECKERBOARD[0]*CHECKERBOARD[1], 3), np.float32)
objp[0, :, :2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2)
_img_shape = None
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.

images = glob.glob('Callibration_fisheye/*.jpg')
for fname in images:
    img = cv2.imread(fname)
    if _img_shape == None:
        _img_shape = img.shape[:2]
    else:
        assert _img_shape == img.shape[:2], "All images must share the same size."

    gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray_image, CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_FAST_CHECK + cv2.CALIB_CB_NORMALIZE_IMAGE)
    # If found, add object points, image points (after refining them)
    if ret == True:
        objpoints.append(objp)
        cv2.cornerSubPix(gray_image, corners, (3, 3), (-1, -1), subpix_criteria)
        imgpoints.append(corners)

N_OK = len(objpoints)
K = np.zeros((3, 3))
D = np.zeros((4, 1))
rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)]
tvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)]
rms, _, _, _, _ = \
    cv2.fisheye.calibrate(
        objpoints,
        imgpoints,
        gray_image.shape[::-1],
        K,
        D,
        rvecs,
        tvecs,
        calibration_flags,
        (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6)
    )
print("Found " + str(N_OK) + " valid images for calibration")
print("DIM = " + str(_img_shape[::-1]))
print("K = np.array(" + str(K.tolist()) + ")")
print("D = np.array(" + str(D.tolist()) + ")")

with open(f'../output/Fisheye_KD_matrix', 'wb') as handle:
    pickle.dump([DIM, K, D], handle)

max_stars_repo_name: EveCharbie/rectangle-labelling

max_issues_repo_name: EveCharbie/rectangle-labelling

max_forks_repo_name: EveCharbie/rectangle-labelling


text:
from itertools import combinations
import networkx as nx
import grinpy as gp

MAX_VALENCY = 4

def enumerate_isomers(carbon_count, acyclic=False):
    """ Enumerate all possible saturated alkane from
        given number of carbons and return as NetworkX Graph object """

    print("Enumerating all possible isomers......")
    randic_indexes = []
    isomers = []

    # enumerate all possible bonding combinations of numeically labeled carbons
    bond_count = carbon_count - 1
    bonds = list(combinations(range(carbon_count), 2))
    bond_combinations = list(combinations(bonds, bond_count))

    for bond_combination in bond_combinations:

        # Create "isomer" as a non-directed graph
        isomer = nx.Graph()
        for bond in bond_combination:
            isomer.add_edge(*bond)

        # remove hypervalent structures
        is_hypervalent = any([degree[1] > MAX_VALENCY for degree in isomer.degree])
        if is_hypervalent:
            continue

        # remove cyclic structures if 'acyclic' is True
        if acyclic and nx.cycle_basis(isomer):
            continue

        # remove duplications by wiener index
        randic_index = gp.randic_index(isomer)
        if (randic_index == float('inf')) or (randic_index in randic_indexes):
            continue
        randic_indexes.append(randic_index)

        isomers.append(isomer)

    print("Enumeration finished!")
    return isomers

reason: import networkx


text:
import numpy as np

class DataDecoder:
    def __init__(self):
        pass

    def __call__(self, line):
        return ([],0)

class CSVDecoder(DataDecoder):
    def __init__(self, delimiter = ',', labelCol = -1):
        self._delimiter = delimiter
        self._labelCol = labelCol

    def __call__(self, line):
        parsed_line = [float(c) for c in line.split(self._delimiter)]
        label = parsed_line[self._labelCol]
        del parsed_line[self._labelCol]
        example = parsed_line

        return np.array(example), int(label)

    def __str__(self):
        return "CSV decoder"

max_stars_repo_name: chelseajohn/dlapplication

max_issues_repo_name: chelseajohn/dlapplication

max_forks_repo_name: chelseajohn/dlapplication


text:
#!/bin/env python
"""
Ensemble verification
=====================

In this tutorial we perform a verification of a probabilistic extrapolation nowcast
using MeteoSwiss radar data.

"""

from datetime import datetime
import matplotlib.pyplot as plt
import numpy as np
from pprint import pprint
from pysteps import io, nowcasts, rcparams, verification
from pysteps.motion.lucaskanade import dense_lucaskanade
from pysteps.postprocessing import ensemblestats
from pysteps.utils import conversion, dimension, transformation
from pysteps.visualization import plot_precip_field

###############################################################################
# Read precipitation field
# ------------------------
#
# First, we will import the sequence of MeteoSwiss ("mch") radar composites.
# You need the pysteps-data archive downloaded and the pystepsrc file
# configured with the data_source paths pointing to data folders.

# Selected case
date = datetime.strptime("201607112100", "%Y%m%d%H%M")
data_source = rcparams.data_sources["mch"]
n_ens_members = 20
n_leadtimes = 6
seed = 24

###############################################################################
# Load the data from the archive
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# The data are upscaled to 2 km resolution to limit the memory usage and thus
# be able to afford a larger number of ensemble members.

root_path = data_source["root_path"]
path_fmt = data_source["path_fmt"]
fn_pattern = data_source["fn_pattern"]
fn_ext = data_source["fn_ext"]
importer_name = data_source["importer"]
importer_kwargs = data_source["importer_kwargs"]
timestep = data_source["timestep"]

# Find the radar files in the archive
fns = io.find_by_date(
    date, root_path, path_fmt, fn_pattern, fn_ext, timestep, num_prev_files=2
)

# Read the data from the archive
importer = io.get_method(importer_name, "importer")
R, _, metadata = io.read_timeseries(fns, importer, **importer_kwargs)

# Convert to rain rate
R, metadata = conversion.to_rainrate(R, metadata)

# Upscale data to 2 km
R, metadata = dimension.aggregate_fields_space(R, metadata, 2000)

# Plot the rainfall field
plot_precip_field(R[-1, :, :], geodata=metadata)
plt.show()

# Log-transform the data to unit of dBR, set the threshold to 0.1 mm/h,
# set the fill value to -15 dBR
R, metadata = transformation.dB_transform(R, metadata, threshold=0.1, zerovalue=-15.0)

# Set missing values with the fill value
R[~np.isfinite(R)] = -15.0

# Nicely print the metadata
pprint(metadata)

###############################################################################
# Forecast
# --------
#
# We use the STEPS approach to produce a ensemble nowcast of precipitation fields.

# Estimate the motion field
V = dense_lucaskanade(R)

# Perform the ensemble nowcast with STEPS
nowcast_method = nowcasts.get_method("steps")
R_f = nowcast_method(
    R[-3:, :, :],
    V,
    n_leadtimes,
    n_ens_members,
    n_cascade_levels=6,
    R_thr=-10.0,
    kmperpixel=2.0,
    timestep=timestep,
    decomp_method="fft",
    bandpass_filter_method="gaussian",
    noise_method="nonparametric",
    vel_pert_method="bps",
    mask_method="incremental",
    seed=seed,
)

# Back-transform to rain rates
R_f = transformation.dB_transform(R_f, threshold=-10.0, inverse=True)[0]

# Plot some of the realizations
fig = plt.figure()
for i in range(4):
    ax = fig.add_subplot(221 + i)
    ax.set_title("Member %02d" % i)
    plot_precip_field(R_f[i, -1, :, :], geodata=metadata, colorbar=False, axis="off")
plt.tight_layout()
plt.show()

###############################################################################
# Verification
# ------------
#
# Pysteps includes a number of verification metrics to help users to analyze
# the general characteristics of the nowcasts in terms of consistency and
# quality (or goodness).
# Here, we will verify our probabilistic forecasts using the ROC curve,
# reliability diagrams, and rank histograms, as implemented in the verification
# module of pysteps.

# Find the files containing the verifying observations
fns = io.archive.find_by_date(
    date,
    root_path,
    path_fmt,
    fn_pattern,
    fn_ext,
    timestep,
    0,
    num_next_files=n_leadtimes,
)

# Read the observations
R_o, _, metadata_o = io.read_timeseries(fns, importer, **importer_kwargs)

# Convert to mm/h
R_o, metadata_o = conversion.to_rainrate(R_o, metadata_o)

# Upscale data to 2 km
R_o, metadata_o = dimension.aggregate_fields_space(R_o, metadata_o, 2000)

# Compute the verification for the last lead time

# compute the exceedance probability of 0.1 mm/h from the ensemble
P_f = ensemblestats.excprob(R_f[:, -1, :, :], 0.1, ignore_nan=True)

###############################################################################
# ROC curve
# ~~~~~~~~~

roc = verification.ROC_curve_init(0.1, n_prob_thrs=10)
verification.ROC_curve_accum(roc, P_f, R_o[-1, :, :])
fig, ax = plt.subplots()
verification.plot_ROC(roc, ax, opt_prob_thr=True)
ax.set_title("ROC curve (+%i min)" % (n_leadtimes * timestep))
plt.show()

###############################################################################
# Reliability diagram
# ~~~~~~~~~~~~~~~~~~~

reldiag = verification.reldiag_init(0.1)
verification.reldiag_accum(reldiag, P_f, R_o[-1, :, :])
fig, ax = plt.subplots()
verification.plot_reldiag(reldiag, ax)
ax.set_title("Reliability diagram (+%i min)" % (n_leadtimes * timestep))
plt.show()

###############################################################################
# Rank histogram
# ~~~~~~~~~~~~~~

rankhist = verification.rankhist_init(R_f.shape[0], 0.1)
verification.rankhist_accum(rankhist, R_f[:, -1, :, :], R_o[-1, :, :])
fig, ax = plt.subplots()
verification.plot_rankhist(rankhist, ax)
ax.set_title("Rank histogram (+%i min)" % (n_leadtimes * timestep))
plt.show()

# sphinx_gallery_thumbnail_number = 5

max_stars_repo_name: AFansGH/pysteps

max_issues_repo_name: AFansGH/pysteps

max_forks_repo_name: AFansGH/pysteps