text:
import warnings

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Line3DCollection
import matplotlib.pyplot as plt
import numpy as np

class VisMatplotlib:
    def __init__(self):
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111, projection='3d')
        self.ax.set_xlim([-5, 5])
        self.ax.set_ylim([-5, 5])
        self.ax.set_zlim([0, 3])
        self.ax.set_xlabel("X")
        self.ax.set_ylabel("Y")
        self.ax.set_zlabel("Z")
        self.plot = None
        self.timeAnnotation = self.ax.annotate("Time", xy=(0, 0), xycoords='axes fraction', fontsize=12, ha='right', va='bottom')

        self.line_color = 0.3 * np.ones(3)

        # Lazy-constructed data for connectivity graph gfx.
        self.graph_edges = None
        self.graph_lines = None
        self.graph = None

    def setGraph(self, edges):
        """Set edges of graph visualization - sequence of (i,j) tuples."""

        # Only allocate new memory if we need to.
        n_edges = len(edges)
        if self.graph_edges is None or n_edges != len(self.graph_edges):
            self.graph_lines = np.zeros((n_edges, 2, 3))
        self.graph_edges = edges

        # Lazily construct Matplotlib object for graph.
        if self.graph is None:
            self.graph = Line3DCollection(self.graph_lines, edgecolor=self.line_color)
            self.ax.add_collection(self.graph)

    def showEllipsoids(self, radii):
        warnings.warn("showEllipsoids not implemented in Matplotlib visualizer.")

    def update(self, t, crazyflies):
        xs = []
        ys = []
        zs = []
        cs = []
        for cf in crazyflies:
            x, y, z = cf.position()
            color = cf.ledRGB
            xs.append(x)
            ys.append(y)
            zs.append(z)
            cs.append(color)

        if self.plot is None:
            self.plot = self.ax.scatter(xs, ys, zs, c=cs)
        else:
            # TODO: Don't use protected members.
            self.plot._offsets3d = (xs, ys, zs)
            self.plot.set_facecolors(cs)
            self.plot.set_edgecolors(cs)
            self.plot._facecolor3d = self.plot.get_facecolor()
            self.plot._edgecolor3d = self.plot.get_edgecolor()

        if self.graph is not None:
            # Update graph line segments to match new Crazyflie positions.
            for k, (i, j) in enumerate(self.graph_edges):
                self.graph_lines[k, 0, :] = xs[i], ys[i], zs[i]
                self.graph_lines[k, 1, :] = xs[j], ys[j], zs[j]
                self.graph.set_segments(self.graph_lines)

        self.timeAnnotation.set_text("{} s".format(t))
        plt.pause(0.0001)

    def render(self):
        warnings.warn("Rendering video not supported in VisMatplotlib yet.")
        return None

max_stars_repo_name: marios-stam/crazyswarm

max_issues_repo_name: marios-stam/crazyswarm

max_forks_repo_name: marios-stam/crazyswarm


text:
# Copyright 2021, Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generates histograms with different total counts and distributions."""

import numpy as np

def generate_non_iid_poisson_counts(
    num_users: int,
    iid_param: float,
    avg_count: float,
    rng: np.random.Generator = np.random.default_rng()
) -> np.ndarray:
  """Randomly generates counts for a set of users from Poisson distributions.

  When `iid_param=0`, all counts are i.i.d. from Poisson(`avg_count`).
  When `iid_param>0`, counts are distributed according to
  Poi(avg_count*Dirichlet(1/iid_param)).
  Larger iid_param means that the distributions of counts are less identical.

  Args:
    num_users: An integer indicating the total number of users. Must be
      positive.
    iid_param: A float which controls the similarity of counts between users.
      Must be non-negative. Larger value means that the count distributions are
      less identical. 0 means that the counts are i.i.d.
    avg_count: A float indicating the expected average count. Must be
      non-negative.
    rng: A Numpy random generator.

  Returns:
    counts: A numpy array of size `num_users` containing the randomly generated
      counts.
  """
  if num_users <= 0:
    raise ValueError(f'num_users must be positive.'
                     f'Found num_users={num_users}.')
  if iid_param < 0:
    raise ValueError(f'iid_param must be non-negative.'
                     f'Found iid_param={iid_param}')
  if avg_count < 0:
    raise ValueError(f'avg_count must be non-negative.'
                     f'Found avg_count={avg_count}')

  if iid_param > 0:
    lambdas = rng.dirichlet(alpha=np.ones(num_users) / iid_param)
    counts = rng.poisson(lam=num_users * lambdas * avg_count)
  else:
    counts = rng.poisson(lam=avg_count, size=num_users)
  return counts

def generate_non_iid_distributions_dirichlet(
    num_users: int,
    ref_distribution: np.ndarray,
    distribution_delta: float,
    rng=np.random.default_rng()) -> np.ndarray:
  """Generate discrete distributions around a reference distribution.

  Args:
    num_users: An integer indicating the total number of users. Must be
      positive.
    ref_distribution: A 1-D `numpy` array representing the reference discrete
      distribution. Must be non-negative and sum to one.
    distribution_delta: A non-negative `float` indicating the level of
      perturbation around the reference distribution.
      distribution_delta=0: All distributions are identical.
    rng: A numpy random generator.

  Returns:
    distributions: A list of Numpy arrays with the same size as
    `ref_distribution`. Contains all the distributions.
    If distribution_delta=0, then all distributions are `ref_distribution`.
    Otherwise, the distributions are generated according to
    Dirichlet(`ref_distribution`/`distribution_delta`)
  """
  if num_users <= 0:
    raise ValueError('num_users must be positive. Found num_users={num_users}.')
  if distribution_delta < 0:
    raise ValueError(f'distribution_delta must be non-negative.'
                     f'Found distribution_delta={distribution_delta}')
  if ref_distribution.ndim != 1:
    raise ValueError(f'ref_distribution must be a 1-D array.'
                     f'Found dimension={ref_distribution.ndim}.')
  if (ref_distribution < 0).any() | (ref_distribution > 1).any():
    raise ValueError('Expecting elements in ref_distribution to be in [0, 1].')
  if np.sum(ref_distribution) != 1:
    raise ValueError(f'ref_distribution should sum up to 1.'
                     f'Found the sum to be {np.sum(ref_distribution)}.')
  if distribution_delta > 0:
    distributions = rng.dirichlet(
        alpha=ref_distribution / distribution_delta, size=num_users)
  else:
    distributions = np.tile(ref_distribution, (num_users, 1))
  return distributions

def generate_histograms(
    num_users: int,
    counts_iid_param: float,
    avg_count: float,
    ref_distribution: np.ndarray,
    hist_iid_param: float,
    rng=np.random.default_rng()) -> np.ndarray:
  """Generate histograms with different total counts and distributions.

  Args:
    num_users: An integer indicating the total number of users. Must be
      positive.
    counts_iid_param: A float which controls the similarity of total counts.
      Must be non-negative.
    avg_count: A float indicating the expected average total count. Must be at
      least 1.
    ref_distribution: reference distribution over the domain
    hist_iid_param: A non-negative float. Level of perturbation around the
      reference distribution.
    rng: A numpy random generator.

  Returns:
    histograms: list of numpy arrays which contains all histograms.
  """
  if num_users <= 0:
    raise ValueError(f'num_users must be positive.'
                     f'Found num_users={num_users}.')
  if counts_iid_param < 0:
    raise ValueError(f'counts_iid_param must be non-negative.'
                     f'Found counts_iid_param={counts_iid_param}')
  if avg_count < 1:
    raise ValueError(f'avg_count must be at least 1.'
                     f'Found avg_count={avg_count}')
  if hist_iid_param < 0:
    raise ValueError(f'hist_iid_param must be non-negative.'
                     f'Found hist_iid_param={hist_iid_param}')
  if ref_distribution.ndim != 1:
    raise ValueError(f'ref_distribution must be a 1-D array.'
                     f'Found dimension={ref_distribution.ndim}.')
  if (ref_distribution < 0).any() | (ref_distribution > 1).any():
    raise ValueError('Expecting elements in ref_distribution to be in [0, 1].')
  if np.sum(ref_distribution) != 1:
    raise ValueError(f'ref_distribution should sum up to 1.'
                     f'Found the sum to be {np.sum(ref_distribution)}.')
  # Make sure that each user has at least 1 item
  counts = generate_non_iid_poisson_counts(num_users, counts_iid_param,
                                           avg_count - 1, rng) + 1
  distributions = generate_non_iid_distributions_dirichlet(
      num_users, ref_distribution, hist_iid_param, rng)
  histograms = []
  for i in range(num_users):
    histograms.append(rng.multinomial(counts[i], distributions[i]))
  return np.array(histograms)

ext: py

max_stars_repo_name: garyxcheng/federated

max_issues_repo_name: garyxcheng/federated

max_forks_repo_name: garyxcheng/federated

reason: import numpy


text:
import math as math
from numpy.lib.scimath import sqrt as csqrt

import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import scipy.signal as sg
from scipy.special import sph_harm

class Target(object):
    """ This is a public, abstract class. All instantiations of targets will inherit and or modify
        a subset of the methods inside of the Target class
    """

    def __init__(self, name, desc, n_pix, anti_aliasing ):
        """ Target constructor
            The target is constructed using the characteristic dimension....

        :param name: Name of target
        :param desc: Description of target
        :param n_pix: The number pixels at which to render target
        :param anti_aliasing: oversampling to reduce aliasing

        :return:
        """
        self.name = name
        self.desc = desc
        self.n_pix = n_pix
        self.anti_aliasing = anti_aliasing

    def get_name(self):
        return self.name

    def get_desc(self):
        return self.desc

    def get_n_pix(self):
        return self.n_pix

    def get_AntiAliasing(self):
        return self.anti_aliasing

class GreyscaleLambertianBeachballTarget(Target):
    """ This class inherits the generic(abstract) Target class and adds to
        it specialised methods specific to this type of target. An instantiation
        of this class will render a greyscale beachball. This target is a spherical,lambertian reflector
        that is neutral (grey) across all wavelengths.
    """
    def __init__(self, diam=1.0, n_sector_pairs=12, min_refl=0.0, max_refl=1.0, n_pix=128, anti_aliasing=1, zero_padding):
        """ Create a greyscale lambertian beachball target.

        :param diam: Diameter of the target in m
        :param n_sector_pairs: Number of dark/light sector pairs
        :param min_refl: Reflectance of the dark sectors
        :param max_refl: Reflectance of the light sectors
        :param n_pix: Number of pixels (horizontal and vertical) to render target
        :param anti_aliasing: is set to 1 by default, this means there is no oversampling. Can be set to an integer
            value to oversample the target and then downsample to n_pix in order to reduce aliasing effects (jagged
            edges) along the sector boundaries.
        :return:
        """
        Target.__init__(self, 'BeachBall', 'Grey Spherical Lambertian', n_pix= n_pix, anti_aliasing= anti_aliasing)

        self.diam = diam
        self.n_sector_pairs = n_sector_pairs
        self.min_refl = min_refl
        self.max_refl = max_refl

    def get_diam(self):
        return self.diam

    def get_n_sector_pairs(self):
        return self.n_sector_pairs

    def __str__(self):
        printString = """ The target is a %s %s with %i sectors, rendered with %i pixels and oversampled by a factor %i."""         % (self.desc, self.name, self.n_sector_pairs, self.n_pix, self.anti_aliasing)
        return str(printString)

    def get_target(self):
        """ Build a reflectance image of the target and calculate surface normals at every pixel

        """
        # Set up pixel relative x-coodinates
        x = np.linspace(-1.0, 1.0, self.n_pix * self.anti_aliasing)
        # Meshgrid the x and y coordinates as the same
        x, y = np.meshgrid(x, x)
        # Calculate the polar coordinate theta of each pixel
        theta = np.arctan2(y, x)
        # Produce a siemens star target with the given number of spokes/sectors
        siemans_star = np.cos(self.Nsector_pairs * theta)
        # Create an array that will become a target mask
        mask = np.ones(siemans_star.shape)
        # Make the mask binary by taking the sign of the siemens star
        siemans_star =  np.sign(siemans_star)/2.0 + 0.5
        # Set all value outside the unit circle to the new value
        circle = np.sqrt(x**2 + y**2) > 1.0
        mask[circle] = 0.0
        # downsample if aliasing requested
        if self.anti_aliasing > 1.0:
            the_filter = np.ones((self.anti_aliasing, self.anti_aliasing)) / self.anti_aliasing**2
            # Apply 2D filter convolution
            siemans_star = sg.convolve2d(siemans_star, the_filter, mode = 'full')
            # Convole the mask as well
            mask = sg.convolve2d(mask, the_filter, mode = 'full')
            siemans_star = siemans_star[0.0::self.anti_aliasing, ::self.anti_aliasing]
            mask = mask[0.0::self.anti_aliasing, ::self.anti_aliasing]
        x = np.linspace(-1.0, 1.0, siemans_star.shape[0])
        y = np.linspace(-1.0, 1.0, siemans_star.shape[1])
        x, y = np.meshgrid(x, y)
        # Create blank list of normal vector components
        normal_vector_list = [[],[],[]]
        normal_vector_list[0] = x
        normal_vector_list[1] = y
        normal_vector_list[2] = (csqrt(1.0 - x**2 - y**2)).real
        # Save reflectance map, normal vectors and mask in self
        self.normal_vector_list = normal_vector_list
        self.siemens_star = siemans_star
        self.mask = mask
        return normal_vector_list, mask, siemans_star

test = GreyscaleLambertianBeachballTarget(Npix=128*4, anti_aliasing=1)

vector, grey_scale_mask, star = test.get_target()

xn = vector[0] * grey_scale_mask
yn = vector[1] * grey_scale_mask
zn = vector[2] * grey_scale_mask

def render_target(self, vza, svaz, normal_vector, rad_env, rad_fields):
    """
    This function will render a target in a Radiant Environment Map (REM)

    """

    if vza >= 0.0 and vza <= 90.0:

        targ_REM = rad_env.compilation[1].rad_fields[0]

        polar_ang = np.linspace(0.0, np.pi, targ_REM.shape[0])
        azi_ang = np.linspace(0.0, np.pi, targ_REM.shape[1])
        sph_fit = sph_harm(2, 2, azi_ang, polar_ang)

        targ_SHREM = rad_env.compilation[1].rad_fields[0] *sph_fit
        targ_edir = rad_env.compilation[1].edir

    elif vza >90.0 and vza <=180.0:

        targ_REM = rad_env.compilation[0].rad_fields[0]

        polar_ang = np.linspace(0.0, np.pi, targ_REM.shape[0])
        azi_ang = np.linspace(0.0, np.pi, targ_REM.shape[1])
        sph_fit = sph_harm(2, 2, azi_ang, polar_ang)

        targ_SHREM = rad_env.compilation[0].rad_fields[0] *sph_fit
        targ_edir = rad_env.compilation[0].edir
    else:

        pass # log an error / warning here

    target_mask = [[]]
    at_target_radiance = [[]]

#   Compute the sun-pointing vector

    sza = rad_env.sza
    sun_vectors = [[-1.0 * np.sin(np.deg2rad(sza))], [0.0], [np.cos(np.deg2rad(sza))]]
        REM = np.ones((5,5))
#   Compute the polar and azimuth angles for the REM
#     polar_ang = np.linspace(0.0, np.pi, REM.shape[0])  #
#     azi_ang = np.linspace(0.0, np.pi, REM.shape[1])

#   Do vector geometry

#   Rotate beachball surface normals into the VZA
#   Rotating into the VZA is a rotation about the x-axis

    x_rot = np.array(np.pi-vza)

#     Then rotate surface normals into the solar-relative view
#     azimuth angle. This is a rotation about the z-axis

    z_rot = svaz

    new_normal_vectors = ([[normal_vector[0]], [normal_vector[1]], [normal_vector[2]]] *  x_rot) * z_rot

    cos_to_sun_vectors = new_normal_vectors * sun_vectors
    cos_to_sun_vectors[cos_to_sun_vectors < 0.0] = 0.0

    # PSEUDOCODE

    # if target is spectrally neutral then replicate the reflectance matrix in the spectral dimension use np.tile
    #
    # extract band number from band defintion from REM this is then saved in REMBands
    # extract band number from band model ,this is then saved in Targbands
    #
    # check bands function -> if REM bands in Targ bands return true else retutrn false, and issue warning
    #
new_render = render_target(vector)

max_stars_repo_name: derekjgriffith/MORTICIA

max_issues_repo_name: derekjgriffith/MORTICIA

max_forks_repo_name: derekjgriffith/MORTICIA

reason: import numpy,from numpy,import scipy,from scipy


text:
import pyrealsense2 as rs
import numpy as np
import cv2
X = 1920
Y = 1080
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, X, Y, rs.format.bgr8, 30)

pipeline.start(config)

#cap = cv2.VideoCapture(4)
frameId = 0
while(True):

    frames = pipeline.wait_for_frames()
    color_frame = frames.get_color_frame()
    if not color_frame:
        continue

    color_image = np.asanyarray(color_frame.get_data())

    # Capture frame-by-frame
    # ret, frame = cap.read()

    # Our operations on the frame come here
    # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    show_image = cv2.resize(color_image, (X/2, Y/2))                # Resize image
    cv2.imshow('frame',show_image)

    key = cv2.waitKey(10)

    if key & 0xFF == ord('t'):
        filename = "./pic/camera-pic-of-charucoboard-" +  str(int(frameId)) + ".jpg"
        cv2.imwrite(filename, color_image)
        frameId += 1
        cv2.waitKey(100)

    if key & 0xFF == ord('q'):
        break

# When everything done, release the capture
# cap.release()
cv2.destroyAllWindows()
# cv2.waitKey(1) &

max_stars_repo_name: andy-Chien/ArucoMark

max_issues_repo_name: andy-Chien/ArucoMark

max_forks_repo_name: andy-Chien/ArucoMark


text:
import numpy as np
import gym
import torch
from utils.others import NormalizedActions

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

class Q_estimator:
    def __init__(self, config, agent, best_uncertain):
        self.config = config
        self.agent = agent
        self.best_uncertain = torch.FloatTensor(best_uncertain.reshape(1, -1)).to(device)

        self.eval_env = gym.make(self.config['env'])
        self.eval_env._max_episode_steps = 20000
        self.eval_env = NormalizedActions(self.eval_env)
        self.eval_env.seed(self.config['seed'] + 100)
        self.eval_env.action_space.seed(self.config['seed'])

        self.all_action = []
        num = int(100 / self.config['state_action_pairs'])
        for x in range(num, 100 + num, num):
            action_list = self.get_action_list(x, self.eval_env)
            self.all_action.append(action_list)

    def get_action_list(self, random_step, eval_env):
        action_list = []
        eval_env.seed(self.config['seed'] + 100)
        state, done = eval_env.reset(), False
        for x in range(random_step):
            action = self.agent.select_action(np.array(state),
                                              uncertain=self.best_uncertain)
            state, reward, done, _ = eval_env.step(action)
            action_list.append(action)
        return action_list

    def cal_Q_bias(self, action_list, MC_samples, max_mc_steps, eval_env):
        Q_mc = []
        for x in range(MC_samples):
            eval_env.seed(self.config['seed'] + 100)
            state, done = eval_env.reset(), False
            for action in action_list:
                last_state = state
                last_state_action = action
                state, reward, done, _ = eval_env.step(action)
            Q_mean, _ = self.agent.get_mean_std(torch.FloatTensor(last_state.reshape(1, -1)).to(device),
                                                torch.FloatTensor(last_state_action.reshape(1, -1)).to(device),
                                                self.best_uncertain)
            total_reward = reward
            for y in range(max_mc_steps):
                state_ = torch.FloatTensor(state.reshape(1, -1)).to(device)
                action, log_prob, _, _, _ = self.agent.get_action_log_prob(state_, self.best_uncertain)
                state, reward, done, _ = eval_env.step(action.cpu().data.numpy().flatten())
                logprob = float(log_prob)
                temperature = float(self.agent.temperature(self.best_uncertain))
                total_reward += (reward - logprob * temperature) * self.agent.discount ** (y + 1)
                if done:
                    break
            Q_mc.append(total_reward)
        bias = float(Q_mean) - float(np.mean(Q_mc))
        return bias, np.mean(Q_mc)

    def cal_norm_bias(self):
        bias_list = []
        Q_mc_list = []
        for actions in self.all_action:
            bias, Q_mc = self.cal_Q_bias(actions,
                                         MC_samples=self.config['MC_samples'],
                                         max_mc_steps=self.config['max_mc_steps'],
                                         eval_env=self.eval_env)
            bias_list.append(bias)
            Q_mc_list.append(Q_mc)
        norm_bias = np.array(bias_list) / abs(np.mean(Q_mc_list))
        norm_mean_bias = np.mean(norm_bias)
        norm_std_bias = np.std(norm_bias)
        return norm_mean_bias, norm_std_bias

max_stars_repo_name: ihuhuhu/RAC

max_issues_repo_name: ihuhuhu/RAC

max_forks_repo_name: ihuhuhu/RAC


text:
import logging

from pathlib import Path

import numpy as np

import simulacra as si
import simulacra.units as u

FILE_NAME = Path(__file__).stem
OUT_DIR = Path(__file__).parent / "out" / FILE_NAME

if __name__ == "__main__":
    with si.utils.LogManager(
        "simulacra",
        stdout_logs=True,
        stdout_level=logging.DEBUG,
        file_dir=OUT_DIR,
        file_logs=False,
    ) as logger:
        x = np.linspace(0, 10, 1000)
        y = [np.sin(x), np.cos(x), np.arctan(x)]
        figman = si.vis.xy_plot(
            "test",
            x,
            *y,
            line_kwargs=({"linestyle": "-"}, {"linestyle": ":", "color": "teal"}, None),
            line_labels=(r"$\sin(x)$", r"$\cos(x)$", r"$\arctan(x)$"),
            x_unit=1,
            y_unit="mm",
            hlines=(-0.5, 0.2, 0.33),
            hline_kwargs=({"color": "blue"}, {"color": "orange"}, None),
            vlines=(2, 4, u.twopi),
            vline_kwargs=(None, {"color": "red", "linestyle": "-."}, None),
            x_extra_ticks=(u.pi, u.pi / 2),
            x_extra_tick_labels=(r"$\pi$", r"$\frac{\pi}{2}$"),
            y_extra_ticks=(0.66, 0.88),
            y_extra_tick_labels=(r"$\alpha$", r"$\beta$"),
            title="foo",
            x_label="bar",
            y_label="$baz$",
            target_dir=OUT_DIR,
        )

max_stars_repo_name: JoshKarpel/simulacra

max_issues_repo_name: JoshKarpel/simulacra

max_forks_repo_name: JoshKarpel/simulacra


text:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from matplotlib.ticker import PercentFormatter
from pylab import rcParams

rcParams['figure.figsize'] = 6.4, 2.5

data = pd.read_csv('D:\\rq2\\results\\csv-log4j2\\log4j2#org.apache.logging.log4j.perf.jmh.FileAppenderBenchmark.logbackAsyncFile#.csv', delimiter=";")

hist = []

for index, row in data.iterrows():
    if row['fork'] == 1:
        for _ in range(int(row['value_count'])):
            hist.append(row['value'])

plt.hist(hist, bins=50, range=[0, 0.000002], weights=np.ones(len(hist)) / len(hist))
plt.gca().yaxis.set_major_formatter(PercentFormatter(1, 0))
plt.xlabel('incovation time [ns]')
plt.xticks([0, 0.0000005, 0.000001, 0.0000015, 0.000002], [0, 500, 1000, 1500, 2000])
plt.tight_layout()
# plt.show()
plt.savefig('export.pdf')

max_stars_repo_name: stewue/masterthesis-evaluation

max_issues_repo_name: stewue/masterthesis-evaluation

max_forks_repo_name: stewue/masterthesis-evaluation


text:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('C:\Code_python\Image\Picture\Tiger.jpg',0)
# img2 = cv2.equalizeHist(img)
hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max()/ cdf.max()
cdf_m = np.ma.masked_equal(cdf,0)
cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
cdf = np.ma.filled(cdf_m,0).astype('uint8')
img2 = cdf[img]
cv2.namedWindow('before')
cv2.imshow('before',img)
cv2.namedWindow('after')
cv2.imshow('after',img2)
cv2.waitKey(0)
cv2.destroyAllWindows()

max_stars_repo_name: pection/InternshipProject

max_issues_repo_name: pection/InternshipProject

max_forks_repo_name: pection/InternshipProject


text:
"""
registration.py
---------------

Functions for registering (aligning) point clouds with ICP and feature registration.

"""

from open3d import *
import numpy as np
import cv2

def icp(source,target,voxel_size,max_correspondence_distance_coarse,max_correspondence_distance_fine,
        method = "colored-icp"):

    """
    Perform pointcloud registration using iterative closest point.

    Parameters
    ----------
    source : An open3d.Pointcloud instance
      6D pontcloud of a source segment
    target : An open3d.Pointcloud instance
      6D pointcloud of a target segment
    method : string
      colored-icp, as in Park, Q.-Y. Zhou, and V. Koltun, Colored Point Cloud
      Registration Revisited, ICCV, 2017 (slower)
      point-to-plane, a coarse to fine implementation of point-to-plane icp (faster)
    max_correspondence_distance_coarse : float
      The max correspondence distance used for the course ICP during the process
      of coarse to fine registration (if point-to-plane)
    max_correspondence_distance_fine : float
      The max correspondence distance used for the fine ICP during the process
      of coarse to fine registration (if point-to-plane)

    Returns
    ----------
    transformation_icp: (4,4) float
      The homogeneous rigid transformation that transforms source to the target's
      frame
    information_icp:
      An information matrix returned by open3d.get_information_matrix_from_ \
      point_clouds function
    """

    assert method in ["point-to-plane","colored-icp"],"point-to-plane or colored-icp"
    if method == "point-to-plane":
        icp_coarse = registration.registration_icp(source, target,
                                                   max_correspondence_distance_coarse, np.identity(4),
                                                   registration.TransformationEstimationPointToPlane())
        icp_fine = registration.registration_icp(source, target,
                max_correspondence_distance_fine, icp_coarse.transformation,
                registration.TransformationEstimationPointToPlane())

        transformation_icp = icp_fine.transformation

    if method == "colored-icp":
        result_icp = registration.registration_colored_icp(source,target,voxel_size, np.identity(4),
                                                           registration.ICPConvergenceCriteria(relative_fitness = 1e-8,
                                                                                relative_rmse = 1e-8, max_iteration = 50))

        transformation_icp = result_icp.transformation

    information_icp = registration.get_information_matrix_from_point_clouds(
        source, target, max_correspondence_distance_fine,
        transformation_icp)

    return transformation_icp, information_icp

def feature_registration(source,target, MIN_MATCH_COUNT = 12):
    """
    Obtain the rigid transformation from source to target
    first find correspondence of color images by performing fast registration
    using SIFT features on color images.
    The corresponding depth values of the matching keypoints is then used to
    obtain rigid transformation through a ransac process.

    Parameters
    ----------
    source : ((n,m) uint8, (n,m) float)
      The source color image and the corresponding 3d pointcloud combined in a list
    target : ((n,m) uint8, (n,m) float)
      The target color image and the corresponding 3d pointcloud combined in a list
    MIN_MATCH_COUNT : int
      The minimum number of good corresponding feature points for the algorithm  to
      trust the pairwise registration result with feature matching only

    Returns
    ----------
    transform: (4,4) float or None
      The homogeneous rigid transformation that transforms source to the target's
      frame
      if None, registration result using feature matching only cannot be trusted
      either due to no enough good matching feature points are found, or the ransac
      process does not return a solution

    """
    cad_src, depth_src = source
    cad_des, depth_des = target

    # Initiate SIFT detector
    sift = cv2.xfeatures2d.SIFT_create()

    # find the keypoints and descripto  rs with SIFT
    kp1, des1 = sift.detectAndCompute(cad_src,None)
    kp2, des2 = sift.detectAndCompute(cad_des,None)

    # find good mathces
    bf = cv2.BFMatcher()
    matches = bf.knnMatch(des1,des2, k=2)
    good = []
    for m,n in matches:
        if m.distance < 0.7*n.distance:
            good.append(m)

    # if number of good matching feature point is greater than the MIN_MATCH_COUNT

    if len(good)>MIN_MATCH_COUNT:
        src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
        dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)
        M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
        matchesMask = mask.ravel().tolist()

        bad_match_index = np.where(np.array(matchesMask) == 0)
        src_index=np.vstack(src_pts).squeeze()
        src_index = np.delete(src_index, tuple(bad_match_index[0]), axis=0)
        src_index[:,[0, 1]] = src_index[:,[1, 0]]
        src_index = tuple(src_index.T.astype(np.int32))

        src_depths = depth_src[src_index]
        dst_index=np.vstack(dst_pts).squeeze()
        dst_index = np.delete(dst_index, tuple(bad_match_index[0]), axis=0)
        dst_index[:,[0, 1]] = dst_index[:,[1, 0]]
        dst_index = tuple(dst_index.T.astype(np.int32))
        dst_depths = depth_des[dst_index]

        dst_good=[]
        src_good=[]
        dst_depths=dst_depths[matchesMask>0][0]
        src_depths=src_depths[matchesMask>0][0]

        for i in xrange(len(dst_depths)):
            if np.sum(dst_depths[i])!=0 and np.sum(src_depths[i])!=0:
                dst_good.append(dst_depths[i].tolist())
                src_good.append(src_depths[i].tolist())

        # get rigid transforms between 2 set of feature points through ransac
        transform = match_ransac(np.asarray(src_good),np.asarray(dst_good))
        return transform

    else:
        return None

def match_ransac(p, p_prime, tol = 0.01):
    """
    A ransac process that estimates the transform between two set of points
    p and p_prime.
    The transform is returned if the RMSE of the smallest 70% is smaller
    than the tol.

    Parameters
    ----------
    p : (n,3) float
      The source 3d pointcloud as a numpy.ndarray
    target : (n,3) float
      The target 3d pointcloud as a numpy.ndarray
    tol : float
      A transform is considered found if the smallest 70% RMSE error between the
      transformed p to p_prime is smaller than the tol

    Returns
    ----------
    transform: (4,4) float or None
      The homogeneous rigid transformation that transforms p to the p_prime's
      frame
      if None, the ransac does not find a sufficiently good solution

    """

    leastError = None
    R = None
    t= None
    # the smallest 70% of the error is used to compute RMSE
    k= int(len(p)*0.7)
    assert len(p) == len(p_prime)
    R_temp,t_temp = rigid_transform_3D(p,p_prime)
    R_temp = np.array(R_temp)
    t_temp = (np.array(t_temp).T)[0]
    transformed = (np.dot(R_temp, p.T).T)+t_temp
    error = (transformed - p_prime)**2
    error = np.sum(error, axis=1)
    error = np.sqrt(error)

    RMSE = np.sum(error[np.argpartition(error, k)[:k]])/k
    if RMSE < tol:
        R = R_temp
        t = t_temp

        transform = [[R[0][0],R[0][1],R[0][2],t[0]],
                     [R[1][0],R[1][1],R[1][2],t[1]],
                     [R[2][0],R[2][1],R[2][2],t[2]],
                     [0,0,0,1]]
        return transform

        return None

def rigid_transform_3D(A, B):
    """
    Estimate a rigid transform between 2 set of points of equal length
    through singular value decomposition(svd), return a rotation and a
    transformation matrix

    Parameters
    ----------
    A : (n,3) float
      The source 3d pointcloud as a numpy.ndarray
    B : (n,3) float
      The target 3d pointcloud as a numpy.ndarray

    Returns
    ----------
    R: (3,3) float
      A rigid rotation matrix
    t: (3) float
      A translation vector

    """

    assert len(A) == len(B)
    A=  np.asmatrix(A)
    B=  np.asmatrix(B)
    N = A.shape[0];

    centroid_A = np.mean(A, axis=0)
    centroid_B = np.mean(B, axis=0)

    AA = A - np.tile(centroid_A, (N, 1))
    BB = B - np.tile(centroid_B, (N, 1))
    H = AA.T * BB
    U, S, Vt = np.linalg.svd(H)
    R = Vt.T * U.T

    # reflection case
    if np.linalg.det(R) < 0:
        Vt[2,:] *= -1
        R = Vt.T * U.T

    t = -R*centroid_A.T + centroid_B.T

    return (R, t)

max_stars_repo_name: seu-labview/ObjectDatasetTools

max_issues_repo_name: TommasoBendinelli/ObjectDatasetTools


text:
import numpy as np

def pressure(depth: np.ndarray, latitude: np.ndarray) -> np.ndarray:
    """
    Computes pressure given the depth at some latitude.

    This probably works best in mid-latitude oceans, if anywhere!

    Ref: Saunders, "Practical Conversion of Pressure to Depth",
         J. Phys. Oceanog., April 1981.

    :param depth: Ocean depth in meters
    :param latitude: Latitude in degrees
    :return: Pressure in dbar
    """
    p_lat = np.abs(latitude * np.pi / 180)
    d = np.sin(p_lat)
    c1 = 5.92E-3 + (d * d) * 5.25E-34
    return ((1-c1) - np.sqrt(((1 - c1) ** 2) - (8.84E-6 * depth))) / 4.42E-6

max_stars_repo_name: sghowell/pymbari

max_issues_repo_name: sghowell/pymbari

max_forks_repo_name: sghowell/pymbari


text:
from __future__ import division
from __future__ import print_function

import re
import pandas as pd
import numpy as np
from keras.utils import np_utils
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences

def read_input_csv(train_csv, test_csv, nb_words, maxlen):
    """
    Method to read csv file pairs

    :returns
    X_train (, maxlen)
    Y_train (, 2)
    X_test
    Y_Test
    word_index: will be used later for initing embedding matrix

    """
    train_df = pd.read_csv(train_csv)
    train_df = train_df.sample(frac=1).reset_index(drop=True) # shuffle train
    test_df = pd.read_csv(test_csv)
    print(train_df.head())

    train_X = train_df.text.values.tolist()
    test_X = test_df.text.values.tolist()

    train_y = train_df.label.values
    test_y = test_df.label.values
    nb_classes = len(np.unique(train_y))
    train_Y = np_utils.to_categorical(train_y, nb_classes)
    test_Y = np_utils.to_categorical(test_y, nb_classes)

    # tokenrize should be applied on train+test jointly
    n_ta = len(train_X)
    n_ts = len(test_X)
    print('Instances: train {} vs. test {}'.format(n_ta, n_ts))

    textraw = [line.encode('utf-8') for line in train_X+test_X]  # keras needs str
    token = Tokenizer(nb_words=nb_words)
    token.fit_on_texts(textraw)

    word_index = token.word_index
    print('Found {} unique tokens.'.format(len(word_index)))

    textseq = token.texts_to_sequences(textraw)
    lens = [len(line) for line in textseq]
    print('sentence lens: {}'.format([np.min(lens), np.max(lens), np.percentile(lens, 90)]))

    train_X = pad_sequences(textseq[0:n_ta], maxlen,  padding='post', truncating='post')
    test_X = pad_sequences(textseq[n_ta:], maxlen,  padding='post', truncating='post')

    train_len = np.asarray(lens[0:n_ta], dtype='float32')
    test_len = np.asarray(lens[n_ta:], dtype='float32')

    return train_X, train_Y, test_X, test_Y, word_index, nb_classes, train_len, test_len

def test_pun2():
    """
    test code
    :return:
    """
    dir = "../../data/pun/"
    ta_csv = dir + "train_cv1.csv"
    ts_csv = dir + "validation.csv"
    tps = read_input_csv(ta_csv, ts_csv, nb_words=20000, maxlen=30)

    print(tps[3])
    for tp in tps:
        print(tp.shape)

def test_pun():
    """
    test code
    :return:
    """
    dir = "../../../dl_response_rater/data/pun_of_day/"
    ta_csv = dir + "train1.csv"
    ts_csv = dir + "test1.csv"
    tps = read_input_csv(ta_csv, ts_csv, nb_words=20000, maxlen=30)
    for tp in tps:
        print(tp.shape)

def check_argu():
    dir = "../../../dl_response_rater/data/Argu/csv/"
    ta_csv = dir + "generic_VC048263_training.csv"
    ts_csv = dir + "generic_VC048263_testing.csv"
    read_input_csv(ta_csv, ts_csv, nb_words=20000, maxlen=30)
    # nb_words will be 10000 and maxlen will be 35

def check_ted():
    dir = "../../../dl_response_rater/data/TED/"
    ta_csv = dir + "train1.csv"
    ts_csv = dir + "test1.csv"
    read_input_csv(ta_csv, ts_csv, nb_words=20000, maxlen=30)
    # nb_words 14100 and maxlen 34

def check_asap():
    dir = "../../../dl_response_rater/data/asap2/"
    items = range(1,11)
    for item in items:
        print('item {}'.format(item))
        ta_csv = dir + "train" + str(item) + ".csv"
        ts_csv = dir + "test" + str(item) + ".csv"
        read_input_csv(ta_csv, ts_csv, nb_words=20000, maxlen=30)
    #
    # item     num_wds      len
    # 1        2907         80
    # 2        2720         88
    # 3        2715         66
    # 4        3638         60
    # 5        3550         52
    # 6        3751         54
    # 7        3803         75
    # 8        3803         94
    # 9        4470         97
    # 10       2955         79
if __name__ == '__main__':
    # test_pun()
    # check_argu()
    # check_ted()
    # check_asap()
    test_pun2()


text:
##############################
#	curvefit.py
#	Python Routine to fit a function to some data using Scipy's curvefit.
#
#	Aritra Ghosh
#############################

import numpy as np
import math
import pylab as plt
from scipy.optimize import curve_fit

#define a function to fit
def func(x, a, b):
	return a*np.sin(2*x)+b

#reading in the data
data = plt.genfromtxt("work.txt",names=True)
x_rad = (data["theta"]*math.pi)/180

#fit the data and store the optimized parameters and covariances in two arrays.
popt,pcov = curve_fit(func,x_rad,data["V"])
perr = np.sqrt(np.diag(pcov))

#Generating points using the fitted function
x_fit = np.linspace(45,90,200)
x_fit_rad = (x_fit*math.pi)/180
y_fit = func(x_fit_rad,popt[0],popt[1])

#Plot data and fit to it
plt.scatter(data["theta"],data["V"],label="Data")
plt.plot(x_fit,y_fit,label="Fit",color="r")

#Modify plot
plt.xlabel("$\\theta$")
plt.title("Variation of Visibility (V) with angle of Polarizer 2 to the horizontal ($\\theta$)\n\n")
plt.ylabel("Visibility (in$\%$)")
plt.legend(loc="best")
plt.savefig("fit.png")

#Print Results
print popt
print pcov
print perr

reason: import numpy,from scipy


text:
import matplotlib.image as mpimg
import numpy as np
import cv2
from skimage.feature import hog

# CORE FUNCTIONS FOR VEHICLE DETECTION PROVIDED IN LESSONS
class hog_channels:
    CH0 = 1 << 0
    CH1 = 1 << 1
    CH2 = 1 << 2

# Function to return HOG features and visualization
def get_hog_features(img, orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True):
    # Call with two outputs if vis==True
    if vis == True:
        features, hog_image = hog(img, orientations=orient,
                                  pixels_per_cell=(pix_per_cell, pix_per_cell),
                                  block_norm= 'L2-Hys',
                                  cells_per_block=(cell_per_block, cell_per_block),
                                  transform_sqrt=True,
                                  visualise=vis, feature_vector=feature_vec)
        return features, hog_image
    # Otherwise call with one output
    else:
        features = hog(img, orientations=orient,
                       pixels_per_cell=(pix_per_cell, pix_per_cell),
                       cells_per_block=(cell_per_block, cell_per_block),
                       block_norm= 'L2-Hys',
                       transform_sqrt=True,
                       visualise=vis, feature_vector=feature_vec)
        return features

# Function to compute binned color features
def bin_spatial(img, size=(32, 32)):
    # Use cv2.resize().ravel() to create the feature vector
    features = cv2.resize(img, size).ravel()
    # Return the feature vector
    return features

# Function that estimates bin range depending on the color and datatype
# please check https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html for information
def color2bin_range(color_space='RGB'):
    # First, check datatype
    ch0_range = ch1_range = ch2_range = (0, 256)
    if (color_space == 'HSV') | (color_space == 'HLS'):
        ch0_range = (0, 180)

    return ch0_range, ch1_range, ch2_range

# Function to compute color histogram features
def color_hist(img, nbins=32, ch0_range=(0, 256), ch1_range=(0, 256), ch2_range=(0, 256)):

    # Compute the histogram of the color channels separately
    channel1_hist = np.histogram(img[:,:,0], bins=nbins, range=ch0_range)
    channel2_hist = np.histogram(img[:,:,1], bins=nbins, range=ch1_range)
    channel3_hist = np.histogram(img[:,:,2], bins=nbins, range=ch2_range)

    # Concatenate the histograms into a single feature vector
    hist_features = np.concatenate((channel1_hist[0], channel2_hist[0], channel3_hist[0]))
    return hist_features, channel1_hist, channel2_hist, channel3_hist

# Function to extract features from an image
def extract_features(image, color_space='RGB',
                     spatial_size=(32, 32), hist_bins=32,
                     orient=9, pix_per_cell=8, cell_per_block=2, hog_channel=0,
                     spatial_feat=True, hist_feat=True, hog_feat=True):
    file_features = []

    if color_space != 'RGB':
        feature_image = cv2.cvtColor(image, eval('cv2.COLOR_RGB2'+color_space))
    else:
        feature_image = np.copy(image)
    # Spatial features
    if spatial_feat == True:
        spatial_features = bin_spatial(feature_image, size=spatial_size)
        file_features.append(spatial_features)

    # Histogram features
    if hist_feat == True:
        # Identify correct histogram bin ranges for each channel
        ch0_hist_range, ch1_hist_range, ch2_hist_range = color2bin_range(color_space=color_space)
        hist_features = color_hist(feature_image, nbins=hist_bins,
                                   ch0_range=ch0_hist_range, ch1_range=ch1_hist_range, ch2_range=ch2_hist_range)[0]
        file_features.append(hist_features)

    # HOG features
    if hog_feat == True:
        hog_features = []
        if (hog_channel & hog_channels.CH0) != 0:
            hog_features.extend(get_hog_features(feature_image[:,:,0], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True))
        if (hog_channel & hog_channels.CH1) != 0:
            hog_features.extend(get_hog_features(feature_image[:,:,1], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True))
        if (hog_channel & hog_channels.CH2) != 0:
            hog_features.extend(get_hog_features(feature_image[:,:,2], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True))

        file_features.append(hog_features)

    return file_features

# Function that takes an image,
# start and stop positions in both x and y,
# window size (x and y dimensions),
# and overlap fraction (for both x and y)
def slide_window(img, x_start_stop=[None, None], y_start_stop=[None, None], xy_window=(64, 64), xy_overlap=(0.5, 0.5)):
    # If x and/or y start/stop positions not defined, set to image size
    if x_start_stop[0] == None:
        x_start_stop[0] = 0
    if x_start_stop[1] == None:
        x_start_stop[1] = img.shape[1]
    if y_start_stop[0] == None:
        y_start_stop[0] = 0
    if y_start_stop[1] == None:
        y_start_stop[1] = img.shape[0]
    # Compute the span of the region to be searched
    xspan = x_start_stop[1] - x_start_stop[0]
    yspan = y_start_stop[1] - y_start_stop[0]
    # Compute the number of pixels per step in x/y
    nx_pix_per_step = np.int(xy_window[0]*(1 - xy_overlap[0]))
    ny_pix_per_step = np.int(xy_window[1]*(1 - xy_overlap[1]))
    # Compute the number of windows in x/y
    nx_buffer = np.int(xy_window[0]*(xy_overlap[0]))
    ny_buffer = np.int(xy_window[1]*(xy_overlap[1]))
    nx_windows = np.int((xspan-nx_buffer)/nx_pix_per_step)
    ny_windows = np.int((yspan-ny_buffer)/ny_pix_per_step)
    # Initialize a list to append window positions to
    window_list = []
    # Loop through finding x and y window positions
    # Note: you could vectorize this step, but in practice
    # you'll be considering windows one by one with your
    # classifier, so looping makes sense
    for ys in range(ny_windows):
        for xs in range(nx_windows):
            # Calculate window position
            startx = xs*nx_pix_per_step + x_start_stop[0]
            endx = startx + xy_window[0]
            starty = ys*ny_pix_per_step + y_start_stop[0]
            endy = starty + xy_window[1]

            # Append window position to list
            window_list.append(((startx, starty), (endx, endy)))
    # Return the list of windows
    return window_list

# Define a function to draw bounding boxes
def draw_boxes(img, bboxes, color=(0, 0, 255), thick=6):
    # Make a copy of the image
    imcopy = np.copy(img)
    # Iterate through the bounding boxes
    for bbox in bboxes:
        # Draw a rectangle given bbox coordinates
        cv2.rectangle(imcopy, bbox[0], bbox[1], color, thick)
    # Return the image copy with boxes drawn
    return imcopy

def add_heat(heatmap, bbox_list):
    # Iterate through list of bboxes
    for box in bbox_list:
        # Add += 1 for all pixels inside each bbox
        # Assuming each "box" takes the form ((x1, y1), (x2, y2))
        heatmap[box[0][1]:box[1][1], box[0][0]:box[1][0]] += 1

    # Return updated heatmap
    return heatmap

def draw_labeled_bboxes(img, labels):
    # Iterate through all detected cars
    for car_number in range(1, labels[1]+1):
        # Find pixels with each car_number label value
        nonzero = (labels[0] == car_number).nonzero()
        # Identify x and y values of those pixels
        nonzeroy = np.array(nonzero[0])
        nonzerox = np.array(nonzero[1])
        # Define a bounding box based on min/max x and y
        bbox = ((np.min(nonzerox), np.min(nonzeroy)), (np.max(nonzerox), np.max(nonzeroy)))
        # Draw the box on the image
        cv2.rectangle(img, bbox[0], bbox[1], (0,0,255), 6)
    # Return the image
    return img

max_stars_repo_name: MaxEtzo/SDC-Vehicle-Detection

max_issues_repo_name: MaxEtzo/SDC-Vehicle-Detection

max_forks_repo_name: MaxEtzo/SDC-Vehicle-Detection


text:
from sys import argv
from os import path
import numpy as np

def reindex_vertices(v, iv):
    min_i, max_i = np.min(iv), np.max(iv)
    return v[min_i - 1:max_i], iv - (min_i - 1)

def process_mesh(filename, v, vt, vn, mesh):
    print(f"Processing: {filename}")
    v, iv = reindex_vertices(v, mesh[..., 0])
    vt, ivt = reindex_vertices(vt, mesh[..., 1])
    vn, ivn = reindex_vertices(vn, mesh[..., 2])
    indices = np.dstack([iv, ivt, ivn])
    with open(filename, "w") as file:
        for x in v + vt + vn:
            print(x, end="", file=file)
        print("g mesh", file=file)
        for face in indices:
            print("f", end="", file=file)
            for x, y, z in face:
                print(f" {x}/{y}/{z}", end="", file=file)
            print(file=file)

if __name__ == "__main__":
    v = []
    vn = []
    vt = []
    meshes = {}
    with open(argv[1], "r") as file:
        for line in file.readlines():
            if line.startswith("v "):
                v.append(line)
            elif line.startswith("vn "):
                vn.append(line)
            elif line.startswith("vt "):
                vt.append(line)
            elif line.startswith("usemtl "):
                name = f"Mesh.{len(meshes):05}.{'.'.join(line.split()[1:])}"
                meshes[name] = []
            elif line.startswith("f "):
                # v/vt/vn
                meshes[name].append([[int(x) for x in v.split('/')] for v in line.split()[1:]])
    for name, mesh in meshes.items():
        filename = f"{path.dirname(argv[1])}/{name}.obj"
        process_mesh(filename, v, vt, vn, np.array(mesh))

max_stars_repo_name: neverfelly/LuisaRender

max_issues_repo_name: neverfelly/LuisaRender

max_forks_repo_name: neverfelly/LuisaRender


text:
from sage.all import *

caesar = AffineCryptosystem(AlphabeticStrings())
a, b = (1, 3)

EncObject = caesar.encoding("AttackAtDawn")
print(EncObject)

Ciphertext = caesar.enciphering(a, b, EncObject)
print(Ciphertext)

Plaintext = caesar.deciphering(a, b, Ciphertext)
print(Plaintext)

reason: from sage


text:
import time

import cv2
import argparse
import numpy as np
import warnings

warnings.filterwarnings('ignore')

class YoloV5Face:
    def __init__(self, yolo_type, confThreshold=0.5, nmsThreshold=0.5, objThreshold=0.5):
        anchors = [[4, 5, 8, 10, 13, 16], [23, 29, 43, 55, 73, 105], [146, 217, 231, 300, 335, 433]]
        num_classes = 1
        self.nl = len(anchors)
        self.na = len(anchors[0]) // 2
        self.no = num_classes + 5 + 10
        self.grid = [np.zeros(1)] * self.nl
        self.stride = np.array([8., 16., 32.])
        self.anchor_grid = np.asarray(anchors, dtype=np.float32).reshape(self.nl, -1, 2)
        self.inpWidth = 640
        self.inpHeight = 640
        self.net = cv2.dnn.readNet(yolo_type + '-face.onnx')
        self.confThreshold = confThreshold
        self.nmsThreshold = nmsThreshold
        self.objThreshold = objThreshold

    def _make_grid(self, nx=20, ny=20):
        xv, yv = np.meshgrid(np.arange(ny), np.arange(nx))
        return np.stack((xv, yv), 2).reshape((-1, 2)).astype(np.float32)

    def postprocess(self, frame, outs):
        frameHeight = frame.shape[0]
        frameWidth = frame.shape[1]
        ratioh, ratiow = frameHeight / self.inpHeight, frameWidth / self.inpWidth
        # Scan through all the bounding boxes output from the network and keep only the
        # ones with high confidence scores. Assign the box's class label as the class with the highest score.

        confidences = []
        boxes = []
        landmarks = []
        for detection in outs:
            confidence = detection[15]
            # if confidence > self.confThreshold and detection[4] > self.objThreshold:
            if detection[4] > self.objThreshold:
                center_x = int(detection[0] * ratiow)
                center_y = int(detection[1] * ratioh)
                width = int(detection[2] * ratiow)
                height = int(detection[3] * ratioh)
                left = int(center_x - width / 2)
                top = int(center_y - height / 2)

                confidences.append(float(confidence))
                boxes.append([left, top, width, height])

        indices = cv2.dnn.NMSBoxes(boxes, confidences, self.confThreshold, self.nmsThreshold)
        result_boxes = []
        for i in indices:
            box = boxes[i]
            left = box[0]
            top = box[1]
            width = box[2]
            height = box[3]
            result_boxes.append([left, top, left + width, top + height])

        return result_boxes

    def detect(self, srcimg):
        blob = cv2.dnn.blobFromImage(srcimg, 1 / 255.0, (self.inpWidth, self.inpHeight), [0, 0, 0], swapRB=True,
                                     crop=False)
        # Sets the input to the network
        self.net.setInput(blob)

        # Runs the forward pass to get output of the output layers
        outs = self.net.forward(self.net.getUnconnectedOutLayersNames())[0]

        # inference output
        outs[..., [0, 1, 2, 3, 4, 15]] = 1 / (1 + np.exp(-outs[..., [0, 1, 2, 3, 4, 15]]))  ###sigmoid
        row_ind = 0
        for i in range(self.nl):
            h, w = int(self.inpHeight / self.stride[i]), int(self.inpWidth / self.stride[i])
            length = int(self.na * h * w)
            if self.grid[i].shape[2:4] != (h, w):
                self.grid[i] = self._make_grid(w, h)

            g_i = np.tile(self.grid[i], (self.na, 1))
            a_g_i = np.repeat(self.anchor_grid[i], h * w, axis=0)
            outs[row_ind:row_ind + length, 0:2] = (outs[row_ind:row_ind + length, 0:2] * 2. - 0.5 + g_i) * int(
                self.stride[i])
            outs[row_ind:row_ind + length, 2:4] = (outs[row_ind:row_ind + length, 2:4] * 2) ** 2 * a_g_i

            row_ind += length
        return outs

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--yolo_type', type=str, default='yolov5m', choices=['yolov5s', 'yolov5m', 'yolov5l'],
                        help="yolo type")
    parser.add_argument("--imgpath", type=str, default='selfie.jpg', help="image path")
    parser.add_argument('--confThreshold', default=0.3, type=float, help='class confidence')
    parser.add_argument('--nmsThreshold', default=0.5, type=float, help='nms iou thresh')
    parser.add_argument('--objThreshold', default=0.3, type=float, help='object confidence')
    args = parser.parse_args()

    yolonet = YoloV5Face(args.yolo_type, confThreshold=args.confThreshold, nmsThreshold=args.nmsThreshold,
                         objThreshold=args.objThreshold)
    srcimg = cv2.imread(args.imgpath)
    start = time.time()
    dets = yolonet.detect(srcimg)
    print("fps is :", (time.time() - start))
    srcimg = yolonet.postprocess(srcimg, dets)

    winName = 'Deep learning object detection in OpenCV'
    cv2.namedWindow(winName, 0)
    cv2.imshow(winName, srcimg)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

max_stars_repo_name: wsh-nie/tools

max_issues_repo_name: wsh-nie/tools

max_forks_repo_name: wsh-nie/tools


text:
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
import logging
from victorinox import victorinox
import pickle
from sklearn.svm import SVC
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
import numpy as np
import time
from scipy import spatial
import math
import os
from sklearn.linear_model import SGDClassifier
from sklearn.calibration import CalibratedClassifierCV
import heapq
from sklearn.neighbors import KNeighborsClassifier
from sklearn import metrics

#enable logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

class MyIter(object):
    path=""
    def __init__(self,fp):
        self.path=fp

    def __iter__(self):
        # path = datapath(self.path)
        with open(self.path, 'r', encoding='utf-8') as fin:
            for line in fin:
               yield line

tool=victorinox()

datapath_staffs=r"data/dataset_lower_clean_stem_group_staffs.csv"
datapath_sentences=r"data/dataset_lower_clean_stem_group_staffs_sentences.csv"
tfidf_vectors=r"data/tfidf_group_vectors.csv"
tfidf_model=r"data/tfidf_group_model.pkl"
knn_model=r"data/knn_group_model.pkl"
csvsummary=r"data/dataset_lower_clean_stem_staff_group_with_periods_summary.csv"

# corpus=MyIter(datapath_sentences)
# vectorizer = CountVectorizer(decode_error="replace")
# vec_train = vectorizer.fit_transform(corpus)
# pickle.dump(vectorizer.vocabulary_,open(tfidf_model,"wb"))
# print("tfidf model saved to %s"%tfidf_model)
# transformer = TfidfTransformer()
# loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
# print("tfidf model loaded from %s"%tfidf_model)
# df=pd.read_csv(datapath_staffs,sep=";")
# dfpegawai=df.ID_PEGAWAI
# res=[]
# with open(datapath_sentences,"r") as f:
#     lines=f.read().splitlines()
#     for x in range(len(lines)):
#         vec=transformer.fit_transform(loaded_vec.fit_transform(np.array([lines[x]]))).toarray()[0].tolist()#tfidf_model.transform([lines[x]]).toarray()[0].tolist()
#         id=[dfpegawai.iloc[x]]
#         res.append(vec+id)
# dfres=pd.DataFrame(res)
# dfres.to_csv(tfidf_vectors,sep=";",index=None,header=None)
# print("tfidf vectors saved to %s"%tfidf_vectors)

# tfidf_model=r"data/tfidf_group_model.pkl"
# tfidf_vectors=r"data/tfidf_group_vectors.csv"
# datapath_staffs=r"data/dataset_lower_clean_stem_group_staffs.csv"
# sentence0="komitmen layan kendali gratifikasi sampai salin surat edar menteri uang laksana pelihara data sumber daya manusia human resources information system seluruh pegawai lingkung menteri uang upacara bendera ingat hari ulang tahun 74 merdeka republik indonesia tahun 2019 tanggal 17 agustus 2019 laksana cuti tahun hari libur nasional dan cuti sama hari raya natal tahun 2019 sampai tetap unit kerja predikat wbk tahun 2019 tingkat menteri uang selenggara rapat kerja raker rapat koordinasi rakor bina mental asn integritas sampai instruksi menteri uang nomor 595 imk 01 2019 tanggal 29 juli 2019 selenggara rapat kerja raker rapat koordinasi rakor mohon dukung video converence keikutsertaan pegawai kptik bmn giat pmo informal meeting tahun 2019 himbauan laksana wajib masuk kerja taat jam kerja lingkung sekretariat jenderal menteri uang himbauan laksana wajib masuk kerja taat jam kerja lingkung sekretariat jenderal menteri uang kuesioner minat beasiswa kumpul berkas ppkpns dp3 lingkung pusintek se tentu tega disiplin atas langgar tentu jam kerja langkah langkah strategis laksana anggar lingkup unit eselon i sekretariat jenderal menteri uang ta 2020 himbauan kait sampai lapor harta kaya pajak pajak pribadi lalu alpha se tentu tega disiplin atas langgar tentu jam kerja upacara bendera rangka ingat hari sumpah pemuda hari oeang republik indonesia 73 tahun 2019 disposisi sekretaris jenderal sampai arah presiden menteri kabinet indonesia maju sampai salin surat edar menteri uang laksana pelihara data sumber daya manusia human resources information system seluruh pegawai lingkung menteri uang sampai surat edar menteri uang laksana pelihara data sumber daya manusia hris seluruh pegawai lingkung menteri uang sampai salin surat edar menteri uang laksana pelihara data sumber daya manusia human resources information system seluruh pegawai lingkung menteri uang surat tugas latih bppk pekan 3 bulan september 2019 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 imbau laksana isi lapor harta kaya lhk lapor pajak pajak pribadi lp2p lalu alpha tawar seleksi sesuai inpassing jabat fungsional pranata uang anggar dapat belanja negara apbn imbau laksana isi lapor harta kaya lhk lapor pajak pajak pribadi lp2p lalu alpha monitoring evaluasi efektivitas organisasi lingkung menteri uang"
# transformer = TfidfTransformer()
# loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
# df=pd.read_csv(datapath_staffs,sep=";")
# sentence_ori=df.iloc[0,1]
# veccorpus0=[0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0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0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.06404761218940949,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.06404761218940949,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08539681625254598,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08539681625254598,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.21349204063136495,0.0,0.0,0.06404761218940949,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.04269840812627299,0.0,0.08539681625254598,0.0,0.0,0.0,0.0,0.0,0.10674602031568248,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.17079363250509197,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08539681625254598,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.04269840812627299,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.10674602031568248,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.40563487719959346,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08539681625254598,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08539681625254598,0.17079363250509197,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.021349204063136496,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
# vec_ori=transformer.fit_transform(loaded_vec.fit_transform(np.array([sentence_ori]))).toarray()[0].tolist()
# vec=transformer.fit_transform(loaded_vec.fit_transform(np.array([sentence0]))).toarray()[0].tolist()
# print(vec_ori==vec)
# print(vec_ori==vec==veccorpus0)

# tfidf_vectors=r"data/tfidf_group_vectors.csv"
# svc_model=r"data/svc_model.pkl"
# df=pd.read_csv(tfidf_vectors,sep=";")
# print('Training classifier')
# model = SVC(kernel='linear', probability=True)
# X=df.iloc[:,:-1]
# y=df.iloc[:,-1]
# model.fit(X, y)
# with open(svc_model, 'wb') as outfile:
#     pickle.dump((model, y), outfile)
# print('Saved classifier model to file "%s"' %svc_model)

# svc_model=r"data/svc_model.pkl"
# tfidf_model=r"data/tfidf_group_model.pkl"
# tfidf_vectors=r"data/tfidf_group_vectors.csv"
# datapath_staffs=r"data/dataset_lower_clean_stem_group_staffs.csv"
# sentence0="komitmen layan kendali gratifikasi sampai salin surat edar menteri uang laksana pelihara data sumber daya manusia human resources information system seluruh pegawai lingkung menteri uang upacara bendera ingat hari ulang tahun 74 merdeka republik indonesia tahun 2019 tanggal 17 agustus 2019 laksana cuti tahun hari libur nasional dan cuti sama hari raya natal tahun 2019 sampai tetap unit kerja predikat wbk tahun 2019 tingkat menteri uang selenggara rapat kerja raker rapat koordinasi rakor bina mental asn integritas sampai instruksi menteri uang nomor 595 imk 01 2019 tanggal 29 juli 2019 selenggara rapat kerja raker rapat koordinasi rakor mohon dukung video converence keikutsertaan pegawai kptik bmn giat pmo informal meeting tahun 2019 himbauan laksana wajib masuk kerja taat jam kerja lingkung sekretariat jenderal menteri uang himbauan laksana wajib masuk kerja taat jam kerja lingkung sekretariat jenderal menteri uang kuesioner minat beasiswa kumpul berkas ppkpns dp3 lingkung pusintek se tentu tega disiplin atas langgar tentu jam kerja langkah langkah strategis laksana anggar lingkup unit eselon i sekretariat jenderal menteri uang ta 2020 himbauan kait sampai lapor harta kaya pajak pajak pribadi lalu alpha se tentu tega disiplin atas langgar tentu jam kerja upacara bendera rangka ingat hari sumpah pemuda hari oeang republik indonesia 73 tahun 2019 disposisi sekretaris jenderal sampai arah presiden menteri kabinet indonesia maju sampai salin surat edar menteri uang laksana pelihara data sumber daya manusia human resources information system seluruh pegawai lingkung menteri uang sampai surat edar menteri uang laksana pelihara data sumber daya manusia hris seluruh pegawai lingkung menteri uang sampai salin surat edar menteri uang laksana pelihara data sumber daya manusia human resources information system seluruh pegawai lingkung menteri uang surat tugas latih bppk pekan 3 bulan september 2019 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 tindak lanjut hasil one on one meeting kait najam anggar menteri uang ta 2019 ta 2020 imbau laksana isi lapor harta kaya lhk lapor pajak pajak pribadi lp2p lalu alpha tawar seleksi sesuai inpassing jabat fungsional pranata uang anggar dapat belanja negara apbn imbau laksana isi lapor harta kaya lhk lapor pajak pajak pribadi lp2p lalu alpha monitoring evaluasi efektivitas organisasi lingkung menteri uang"
# sentence1="sql server"
# print('Testing classifier')
# with open(svc_model, 'rb') as infile:
#     (model, class_names) = pickle.load(infile)
# print('Loaded classifier model from file "%s"' % svc_model)
# transformer = TfidfTransformer()
# loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
# vec=transformer.fit_transform(loaded_vec.fit_transform([sentence0])).toarray()[0].tolist()
# dim=len(loaded_vec.vocabulary)
# vec=np.array(vec).reshape(-1, dim)
# predictions = model.predict_proba(vec)
# pred = model.predict(vec)
# best_class_indices = np.argmax(predictions, axis=1)
# best_class_probabilities = predictions[np.arange(len(best_class_indices)), best_class_indices]
# print("pred:%s"%str(pred))
# print("prediction:%s"%str(predictions))
# print("best_class_indices:%s"%str(best_class_indices))
# print("best_class_probabilities:%s"%str(best_class_probabilities))
# print("employee:%s"%str(class_names[best_class_indices[0]]))

# df=pd.read_csv(tfidf_vectors,sep=";",header=None)
# q="application software level 1 symfoni php framework knowledge update tools itsm sipelantik knowledge update itsm awareness latih data services knowledge update tools itsm sipelantik knowledge update itsm awareness latih data services seminar enterprise architecture cross platform mobile development with xamarin scrum project management workshop syncfusion framework workshop tata kelola tik bas cobit 5 international public service forum 2018 workshop mas atur presiden nomor 16 tahun 2018 ada barang jasa perintah training administrasi manajemen sdm latih uji nasional sertifikasi ahli ada barang jasa perintah"
# q2="application software level 1 symfoni php framework knowledge update tools itsm sipelantik knowledge update itsm awareness latih data services knowledge update tools itsm sipelantik knowledge update itsm awareness latih data services seminar enterprise architecture cross platform mobile development with xamarin scrum project management workshop syncfusion framework workshop tata kelola tik BERbasis cobit 5 international public service forum 2018 workshop mas PERaturAN presiden nomor 16 tahun 2018 PENGadaAN barang jasa pEMerintahAN training administrasi manajemen sdm PElatihAN ujiAN nasional sertifikasi ahli PENGadaAN barang jasa pEMerintahAN "
# q3="oracle"
# transformer = TfidfTransformer()
# loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
# t1=time.time()
# qv=transformer.fit_transform(loaded_vec.fit_transform(np.array([q2]))).toarray()[0].tolist()
# scores=[]
# for idx,row in df.iterrows():
#     v=row[:-1].tolist()
#     score=1 - spatial.distance.cosine(qv,v)
#     scores.append(score)
# print(scores)
# top5=heapq.nlargest(5, range(len(scores)), scores.__getitem__)
# res=df.iloc[top5,-1]
# elapsed=time.time()-t1
# print(res)
# print([scores[x] for x in top5])
# print("elapsed:%f"%elapsed)
# print("########################################")
# print("train KNN")
# t1=time.time()
# knn = KNeighborsClassifier(n_neighbors=len(df))
# knn.fit(df.iloc[:,:-1], df.iloc[:,-1])
# print("train KNN DONE in %f"%(time.time()-t1))
# with open(knn_model,"wb") as f:
#     pickle.dump(knn,f)

# with open(knn_model,"rb") as f:
#     knn_saved=pickle.load(f)
# q3=tool.preprocess_sentence(q3)
# qv=transformer.fit_transform(loaded_vec.fit_transform([q3])).toarray()[0].tolist()
# (distances, indices)=knn_saved.kneighbors([qv],n_neighbors=5)
# indices=indices.tolist()[0]
# res=df.iloc[indices,-1]
# print(res.tolist())
# print(distances.tolist())

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

# datapath_all=r"data/dataset_lower_clean_stem.csv"
# datapath_staffs=r"data/dataset_lower_clean_stem_staff.csv"
# datapath_staff_sentences=r"data/dataset_lower_clean_stem_staff_sentences.csv"
# tfidf_vectors=r"data/tfidf_per_sentence_vectors.csv"
# tfidf_model=r"data/tfidf_per_sentence_model.pkl"
# leader_csv=r"data/leaders.csv"
# svc_model=r"data/svc_per_sentence_model.pkl"
# dataset_vector=r"data/tfidf_per_sentence_vectors.csv"
# dataset_vector_nip=r"data/tfidf_per_sentence_vectors_nip.csv"
# dataset_vector_idseq=r"data/tfidf_per_sentence_vectors_idseq.csv"
# staff_dictionary=r"data/staff_dictionary.pkl"
# staff_dictionary_by_sequence=r"data/staff_dictionary_by_sequence.pkl"
# staff_dictionary_by_sequence_reveresed=r"data/staff_dictionary_by_sequence_reversed.pkl"
# with open(leader_csv,"r") as f:
#     leaders=f.read().splitlines()
# df=pd.read_csv(datapath_all,sep=";")
# X=[]
# y=[]
# for idx,row in df.iterrows():
#     id=row["ID_PEGAWAI"]
#     nip=str(id).split("_")[0]
#     if nip in leaders:
#         continue
#     else:
#         y.append(id)
#         X.append(row["KOMPETENSI"])
# dct_staff={"KOMPETENSI":X,"ID_PEGAWAI":y}
# dct_staff_sentences={"KOMPETENSI":X}
# df_staff=pd.DataFrame(dct_staff)
# df_staff.to_csv(datapath_staffs,sep=";",index=None)
# print("saved %d records to %s"%(len(df_staff),datapath_staffs))
# df_staff_sentences=pd.DataFrame(dct_staff_sentences)
# df_staff_sentences.to_csv(datapath_staff_sentences,sep=";",index=None,header=None)
# print("saved %d sentences to %s"%(len(df_staff_sentences),datapath_staff_sentences))

# corpus=MyIter(datapath_staff_sentences)
# vectorizer = CountVectorizer(decode_error="replace")
# vec_train = vectorizer.fit_transform(corpus)
# pickle.dump(vectorizer.vocabulary_,open(tfidf_model,"wb"))
# print("tfidf model saved to %s"%tfidf_model)
# transformer = TfidfTransformer()
# loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
# print("tfidf model loaded from %s"%tfidf_model)
# df=pd.read_csv(datapath_staffs,sep=";")
# dfpegawai=df.ID_PEGAWAI
# dfcompetence=df.KOMPETENSI
# total=len(dfcompetence)
# res=[]
# batchsize=20000
# it=0
# with open(tfidf_vectors,"a+") as f:
#     for line in corpus:#dfcompetence[it:it+batchsize]:
#         vec=transformer.fit_transform(loaded_vec.fit_transform([line])).toarray()[0].tolist()#tfidf_model.transform([lines[x]]).toarray()[0].tolist()
#         id=[dfpegawai.iloc[it]]
#         l=vec + id
#         f.write(";".join([str(x) for x in l]))
#         f.write("\n")
#         print('\r%d/%d'%(it,total), end="", flush=True)
#         it+=1
#
#

#
#
#
#
#

# with open(staff_dictionary_by_sequence,"rb") as f:
#     kamus=pickle.load(f)
# ids=[int(k) for k,v in kamus.items()]
# corpus=MyIter(dataset_vector_idseq)
# print('Training classifier')
# #model = SVC(kernel='linear', probability=True)
# clf = SGDClassifier()
# batchsize=5000
# i=0
# X=[]
# y=[]
# #y_all=[]
# for line in corpus:
#     if i%batchsize==0:
#         if i!=0:
#             clf.partial_fit(X, y, classes=ids)
#             print('\r partial train on batch %d' % (math.floor(i/batchsize)), end="", flush=True)
#         X=[]
#         y=[]
#     else:
#         parts=line.split(";")
#         vec=parts[0:-1]
#         id=parts[-1].replace("\n","")
#         X.append(vec)
#         y.append(int(id))
#         #y_all.append(id)
#     i+=1
# clf.partial_fit(X, y, classes=ids)
# print('\r partial train on batch %d' % (math.floor(i/batchsize)), end="", flush=True)
# with open(svc_model, 'wb') as outfile:
#     pickle.dump(clf, outfile)
# print('Saved classifier model to file "%s"' %svc_model)
#
#
#
#
#
# sentence0="sampai surat edar menteri uang nomor se 29 mk 1 2019 lapor dialog kerja individu periode i tahun 2020 lingkung menteri uang"
# with open(staff_dictionary_by_sequence,"rb") as f:
#     kamus=pickle.load(f)
# sentence1="sql server"
# print('Testing classifier')
# with open(svc_model, 'rb') as infile:
#     model = pickle.load(infile)
# print('Loaded classifier model from file "%s"' % svc_model)
# transformer = TfidfTransformer()
# loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
# vec=transformer.fit_transform(loaded_vec.fit_transform([sentence0])).toarray()[0].tolist()
# dim=len(loaded_vec.vocabulary)
# vec=np.array(vec).reshape(-1, dim)
# # predictions = model.predict_proba(vec)
# pred = model.predict(vec)
# # best_class_indices = np.argmax(predictions, axis=1)
# # best_class_probabilities = predictions[np.arange(len(best_class_indices)), best_class_indices]
# print("pred:%s"%str(kamus[pred[0]]))
# # print("prediction:%s"%str(predictions))
# # print("best_class_indices:%s"%str(best_class_indices))
# # print("best_class_probabilities:%s"%str(best_class_probabilities))

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

transformer = TfidfTransformer()
loaded_vec = CountVectorizer(decode_error="replace",vocabulary=pickle.load(open(tfidf_model, "rb")))
with open(knn_model,"rb") as f:
    knn_saved=pickle.load(f)
testcorpus=MyIter(csvsummary)
ytrue=[]
ypred=[]
truecount=0
for line in testcorpus:
    parts=line.split(";")
    id=parts[0]
    ytrue.append(id)
    X=parts[1].replace("."," ")
    # q3=tool.preprocess_sentence(q3)
    qv=transformer.fit_transform(loaded_vec.fit_transform([X])).toarray()[0].tolist()
    y_pred=knn_saved.predict([qv])
    ypred.append(y_pred)
    is_true=id==y_pred[0]
    if is_true:
        truecount+=1
    print("%r, accuracy:%f"%((is_true),truecount/411))

print(metrics.accuracy_score(ytrue,ypred))