"""
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)

"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):

    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()
    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.
    if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()

"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)

    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.
    if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)
    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.
    if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)
    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()
    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.
    if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)
    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()
    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.
    if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)
    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()
    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')

"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)
    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()
    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM

    # Merge parameters.
    if algorithm_params:
      if not isinstance(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


"""
"""
"""
API for Correlator Module
This module finds correlation between two time series.
"""

from luminol import exceptions, utils
from luminol.algorithms.correlator_algorithms.all import correlator_algorithms
from luminol.anomaly_detector import AnomalyDetector
from luminol.constants import *
from luminol.modules.time_series import TimeSeries

class Correlator(object):

  def __init__(self, time_series_a, time_series_b, time_period=None, use_anomaly_score=False, algorithm_name=None, algorithm_params=None):
    """
    Initializer
    :param time_series_a: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_series_b: a TimeSeries, a dictionary or a path to a csv file(str).
    :param time_period: a tuple (start, end) representing a data period for considering correlation.
    :param str algorithm_name: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    self.time_series_a = self._load(time_series_a)
    self.time_series_b = self._load(time_series_b)
    if use_anomaly_score:
      self.time_series_a = self._get_anomaly_scores(self.time_series_a)
      self.time_series_b = self._get_anomaly_scores(self.time_series_b)
    if time_period:
      start_p, end_p = time_period
      try:
        self.time_series_a = self.time_series_a.crop(start_p, end_p)
        self.time_series_b = self.time_series_b.crop(start_p, end_p)
      # No data points fall into the specific time range.
      except ValueError:
        raise exceptions.NotEnoughDataPoints
    self._sanity_check()
    self.algorithm_params = {'time_series_a': self.time_series_a, 'time_series_b': self.time_series_b}
    self._get_algorithm_and_params(algorithm_name, algorithm_params)
    self._correlate()

  def _get_anomaly_scores(self, time_series):
    """
    Get anomaly scores of a time series.
    :param TimeSeries time_series: a time_series.
    """
    return AnomalyDetector(time_series, score_only=True).get_all_scores()

  def _load(self, time_series):
    """
    Load time series into a TimeSeries object.
    :param timeseries: a TimeSeries, a dictionary or a path to a csv file(str).
    :return TimeSeries: a TimeSeries object.
    """
    if isinstance(time_series, TimeSeries):
      return time_series
    if isinstance(time_series, dict):
      return TimeSeries(time_series)
    return TimeSeries(utils.read_csv(time_series))

  def _get_algorithm_and_params(self, algorithm_name, algorithm_params):
    """
    Get the specific algorithm and merge the algorithm params.
    :param str algorithm: name of the algorithm to use.
    :param dict algorithm_params: additional params for the specific algorithm.
    """
    algorithm_name = algorithm_name or CORRELATOR_ALGORITHM
    try:
      self.algorithm = correlator_algorithms[algorithm_name]
    except KeyError:
      raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.')
    # Merge parameters.
    if algorithm_params:
      if not isinstance

(algorithm_params, dict):
        raise exceptions.InvalidDataFormat('luminol.Correlator: algorithm_params passed is not a dictionary.')
      else:
        self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())

  def _sanity_check(self):
    """
    Check if the time series have more than two data points.
    """
    if len(self.time_series_a) < 2 or len(self.time_series_b) < 2:
      raise exceptions.NotEnoughDataPoints('luminol.Correlator: Too few data points!')

  def _correlate(self):
    """
    Run correlation algorithm.
    """
    a = self.algorithm(**self.algorithm_params)
    self.correlation_result = a.run()

  def get_correlation_result(self):
    """
    Get correlation result.
    :return CorrelationResult: a CorrelationResult object.
    """
    return self.correlation_result

  def is_correlated(self, threshold=None):
    """
    Compare with a threshold to determine whether two timeseries correlate to each other.
    :return: a CorrelationResult object if two time series correlate otherwise false.
    """
    return self.correlation_result if self.correlation_result.coefficient >= threshold else False


# Embedded file name: scripts/client/gui/impl/gen/view_models/v


def get_model(point_cloud, is_training, bn_decay=None):

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

""" Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


""" Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


# Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', c

    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)


if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)

import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss


import os
import sys
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, '../utils'))
import tensorflow as tf
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg

def placeholder_inputs(batch_size, num_point):
    pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
    labels_pl = tf.placeholder(tf.int32, shape=(batch_size))
    return pointclouds_pl, labels_pl

def get_model(point_cloud, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = poin

t_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    end_points = {}

    l0_xyz = point_cloud
    l0_points = None

    # Set abstraction layers
    l1_xyz, l1_points = pointnet_sa_module_msg(l0_xyz, l0_points, 512, [0.1,0.2,0.4], [16,32,128], [[32,32,64], [64,64,128], [64,96,128]], is_training, bn_decay, scope='layer1', use_nchw=True)
    l2_xyz, l2_points = pointnet_sa_module_msg(l1_xyz, l1_points, 128, [0.2,0.4,0.8], [32,64,128], [[64,64,128], [128,128,256], [128,128,256]], is_training, bn_decay, scope='layer2')
    l3_xyz, l3_points, _ = pointnet_sa_module(l2_xyz, l2_points, npoint=None, radius=None, nsample=None, mlp=[256,512,1024], mlp2=None, group_all=True, is_training=is_training, bn_decay=bn_decay, scope='layer3')

    # Fully connected layers
    net = tf.reshape(l3_points, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp2')
    net = tf_util.fully_connected(net, 40, activation_fn=None, scope='fc3')

    return net, end_points

def get_loss(pred, label, end_points):
    """ pred: B*NUM_CLASSES,
        label: B, """
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=label)
    classify_loss = tf.reduce_mean(loss)
    tf.summary.scalar('classify loss', classify_loss)
    tf.add_to_collection('losses', classify_loss)
    return classify_loss

if __name__=='__main__':
    with tf.Graph().as_default():
        inputs = tf.zeros((32,1024,3))
        net, _ = get_model(inputs, tf.constant(True))
        print(net)