Beispiel #1
0
 def __init__(self, input_path, node_parser, edge_parser, attack_parser,
              solution_parser, **kwargs):
     self.path = input_path
     self.load_nodes = node_parser
     self.load_edges = edge_parser
     if attack_parser:
         self.load_attack = attack_parser
     if solution_parser:
         self.load_solution = solution_parser
     self.nodes_file = kwargs.get(
         'nodes_file', os.path.join(self.path, 'input', 'nodes.txt'))
     self.edges_file = kwargs.get(
         'edges_file', os.path.join(self.path, 'input', 'edges.txt'))
     # initialize the color mapper
     self.color_mapper = {
         name: hex_code
         for name, hex_code in cnames.items()
     }
     colors = kwargs.get('colors', None)
     if colors:
         colors = {k: self.color_mapper.get(k, colors[k]) for k in colors}
         self.tvis = TVis(nodes=self.load_nodes(self.nodes_file),
                          edges=self.load_edges(self.edges_file),
                          colors=colors)
     else:
         self.tvis = TVis(
             nodes=self.load_nodes(self.nodes_file),
             edges=self.load_edges(self.edges_file),
         )
     self.attack_file = kwargs.get(
         'attack_file', os.path.join(self.path, 'input', 'attack.txt'))
     self.solution_file = kwargs.get(
         'solution_file', os.path.join(self.path, 'solution.txt'))
     # initialize the configurations
     self.before_config = None
     self.after_config = None
Beispiel #2
0
from django.db import models
from matplotlib.colors import cnames

# Create your models here.
COLOR_CHOICES = [(name, hex) for name, hex in cnames.items()]


class Tag(models.Model):
    """
    主机标签
    name 标签名
    color 标签颜色
    """
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=10, null=False)
    color = models.CharField(choices=COLOR_CHOICES,
                             default='yellow',
                             max_length=100,
                             null=False)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'tag'

    def __str__(self):
        return self.name
Beispiel #3
0
def get_colordict(filter_:str='dark') -> dict:
    """ return dictionary of colornames by filter """
    return dict((k, v) for k, v in cnames.items() if filter_ in k)
from scipy.cluster.hierarchy import linkage, leaves_list
from scipy.spatial.distance import squareform
from sklearn.manifold import TSNE, MDS


EPSILON = 1e-8

# Define a list of random colors, excluding near-white colors.
NEAR_WHITE_COLORS = ['silver', 'whitesmoke', 'floralwhite', 'aliceblue', \
	'lightgoldenrodyellow', 'lightgray', 'w', 'seashell', 'ivory', \
	'lemonchiffon','ghostwhite', 'white', 'beige', 'honeydew', 'azure', \
	'lavender', 'snow', 'linen', 'antiquewhite', 'papayawhip', 'oldlace', \
	'cornsilk', 'lightyellow', 'mintcream', 'lightcyan', 'lavenderblush', \
	'blanchedalmond', 'lightcoral']
COLOR_LIST = []
for name, hex in cnames.items():
	if name not in NEAR_WHITE_COLORS:
		COLOR_LIST.append(name)
COLOR_LIST = np.array(COLOR_LIST)
np.random.seed(42)
np.random.shuffle(COLOR_LIST)
np.random.seed(None)


def mmd_matrix_plot_DC(dc, condition_from_fn, mmd2_fn, condition_fn, \
	parallel=False, load_data=False, cluster=False, alg='quadratic', max_n=None,\
	sigma=None, cmap='Greys', colorbar=True, cax=None, ticks=[0.0,0.3], \
	filename='mmd_matrix.pdf', ax=None, save_and_close=True):
	"""
	Plot a pairwise MMD matrix.
Beispiel #5
0
# pylint: disable=C0103
import gym
import numpy as np
import serial
import struct

from matplotlib import pyplot as plt
from matplotlib.widgets import Cursor
from matplotlib.colors import cnames
from scipy.integrate import ode
from time import time, sleep
from threading import Thread
from multiprocessing import Process, Pipe, Event
from kusanagi.utils import print_with_stamp, gTrig_np

color_generator = iter(cnames.items())


class Plant(gym.Env):
    def __init__(self, dt=0.1, noise_dist=None,
                 angle_dims=[], name='Plant',
                 *args, **kwargs):
        self.name = name
        self.dt = dt
        self.noise_dist = noise_dist
        self.angle_dims = angle_dims
        self.state = None
        self.u = None
        self.t = 0
        self.done = False
        self.renderer = None
Beispiel #6
0
import sys
import serial
import struct
from enum import Enum

import matplotlib
matplotlib.use('tkagg')
from matplotlib import pyplot as plt
from matplotlib.widgets import Cursor
from matplotlib.colors import cnames
from scipy.integrate import ode
from time import time, sleep
from threading import Thread, Lock
from multiprocessing import Process,Pipe,Event

color_generator = cnames.items()

def gTrig_np(x,angi):
    if type(x) is list:
        x = np.array(x)
    if x.ndim == 1:
        x = x[None,:]
    D = x.shape[1]
    Da = 2*len(angi)
    n = x.shape[0]
    xang = np.zeros((n,Da))
    xi = x[:,angi]
    xang[:,::2] =  np.sin(xi)
    xang[:,1::2] =  np.cos(xi)

    non_angle_dims = list(set(range(D)).difference(angi))
Beispiel #7
0
from itertools import cycle
from sklearn import datasets
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import roc_curve, auc, precision_recall_curve, average_precision_score, accuracy_score
from sklearn.model_selection import train_test_split, StratifiedKFold
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import GaussianNB
from bokeh.plotting import output_file, figure, show, ColumnDataSource
from bokeh.models import HoverTool
from bokeh.layouts import row
import matplotlib.pyplot as plt
from matplotlib.colors import cnames
cnames = dict((k, v) for k, v in cnames.items() if 'dark' in k)


def PCA_2D_labeled(X, y, cnames:list, target_names:list):
    """
    Get a quick 2D rescaled PCA of a labeled dataset
    
    Args:
        X (numpy.ndarray): data
        y (numpy.ndarray): labels
        cnames: a list of color names (str)
        target_names: a list of target names (str)
        
    Returns:
        matplotlib plot object
    """
Beispiel #8
0
import itertools
import sys
from math import floor
from matplotlib.colors import cnames

import classifiers as cl
from IBL import *
import image
import plotter as pl
from spiral import *
import utils

# allcolors = [color for color in sorted(cnames)]
allcolors = [color for key, color in sorted(cnames.items())]


def plot(training_set, test_set, data, header, category):
    categories = list(set([x[category] for x in training_set]))
    pl.plot(
        training_set, test_set, data, utils.without_column(header, category), {
            categories[i]: allcolors[((i + 1) * 41) % len(allcolors)]
            for i in range(len(categories))
        })


def save_spirals(training_set,
                 output,
                 filename,
                 size,
                 show,
                 descriptor=None,