# Path: classification/metadata.py
# PRIMARY_VESSEL_CLASS_COLUMN = 'label'
# VESSEL_CLASS_DETAILED_NAMES = sorted(atomic(schema))
# VESSEL_CATEGORIES = sorted(categories(schema))
# TRAINING_SPLIT = 'Training'
# TEST_SPLIT = 'Test'
#     MAX_WEIGHT = 100.0
# def atomic(obj):
# def categories(obj, include_atomic=True):
# def stable_hash(x):
#     def __init__(self,
#                  metadata_dict,
#                  fishing_ranges_map):
#     def vessel_weight(self, id_):
#     def vessel_label(self, label_name, id_):
#     def ids_for_split(self, split):
#     def weighted_training_list(self,
#                                random_state,
#                                split,
#                                max_replication_factor,
#                                row_filter=lambda row: True,
#                                boundary=1):
#     def fishing_range_only_list(self, random_state, split):
# def read_vessel_time_weighted_metadata_lines(available_ids, lines,
#                                              fishing_range_dict, split):
# def read_vessel_time_weighted_metadata(available_ids,
#                                        metadata_file,
#                                        fishing_range_dict={},
#                                        split=0):
# def read_vessel_multiclass_metadata_lines(available_ids, lines,
#                                           fishing_range_dict):
# def metadata_file_reader(metadata_file):
# def read_vessel_multiclass_metadata(available_ids,
#                                     metadata_file,
#                                     fishing_range_dict={}):
# def find_available_ids(feature_path):
# def parse_date(date):
# def read_fishing_ranges(fishing_range_file):
# def build_multihot_lookup_table():
# def multihot_encode(label):
# class VesselMetadata(object):


import abc
import calendar
import datetime
import logging
import numpy as np
import tensorflow as tf
import tensorflow.metrics as metrics
import pytz
import six
from collections import namedtuple, OrderedDict
from classification import metadata
                 metrics='all'):
        super(LogRegressionObjectiveMAE, self).__init__(metadata_label, name, value_from_id,
                                                     loss_weight, metrics)

    def create_label(self, id_, timestamps):
        return self.value_from_id(id_)

    def masked_mean_loss(self, labels):
        expected, mask = self.expected_and_mask(labels)
        mask = tf.cast(mask, tf.float32)
        count = tf.reduce_sum(mask)
        mean_absolute_error = tf.abs(
            (tf.log(expected + EPSILON) - self.prediction) * mask)
        loss = tf.reduce_sum(mean_absolute_error) / tf.maximum(count, EPSILON)
        return loss



class MultiClassificationObjective(ObjectiveBase):
    def __init__(self,
                 metadata_label,
                 name,
                 vessel_metadata,
                 loss_weight=1.0,
                 metrics='all'):
        super(MultiClassificationObjective, self).__init__(
            metadata_label, name, loss_weight, metrics)
        self.vessel_metadata = vessel_metadata
        self.classes = metadata.VESSEL_CLASS_DETAILED_NAMES
        self.num_classes = metadata.multihot_lookup_table.shape[-1]

# Path: classification/metadata.py
# PRIMARY_VESSEL_CLASS_COLUMN = 'label'
# VESSEL_CLASS_DETAILED_NAMES = sorted(atomic(schema))
# VESSEL_CATEGORIES = sorted(categories(schema))
# TRAINING_SPLIT = 'Training'
# TEST_SPLIT = 'Test'
#     MAX_WEIGHT = 100.0
# def atomic(obj):
# def categories(obj, include_atomic=True):
# def stable_hash(x):
#     def __init__(self,
#                  metadata_dict,
#                  fishing_ranges_map):
#     def vessel_weight(self, id_):
#     def vessel_label(self, label_name, id_):
#     def ids_for_split(self, split):
#     def weighted_training_list(self,
#                                random_state,
#                                split,
#                                max_replication_factor,
#                                row_filter=lambda row: True,
#                                boundary=1):
#     def fishing_range_only_list(self, random_state, split):
# def read_vessel_time_weighted_metadata_lines(available_ids, lines,
#                                              fishing_range_dict, split):
# def read_vessel_time_weighted_metadata(available_ids,
#                                        metadata_file,
#                                        fishing_range_dict={},
#                                        split=0):
# def read_vessel_multiclass_metadata_lines(available_ids, lines,
#                                           fishing_range_dict):
# def metadata_file_reader(metadata_file):
# def read_vessel_multiclass_metadata(available_ids,
#                                     metadata_file,
#                                     fishing_range_dict={}):
# def find_available_ids(feature_path):
# def parse_date(date):
# def read_fishing_ranges(fishing_range_file):
# def build_multihot_lookup_table():
# def multihot_encode(label):
# class VesselMetadata(object):


# Path: classification/models/objectives.py
import abc
import calendar
import datetime
import logging
import numpy as np
import tensorflow as tf
import tensorflow.metrics as metrics
import pytz
import six
from collections import namedtuple, OrderedDict
from classification import metadata

                 metrics='all'):
        super(LogRegressionObjectiveMAE, self).__init__(metadata_label, name, value_from_id,
                                                     loss_weight, metrics)

    def create_label(self, id_, timestamps):
        return self.value_from_id(id_)

    def masked_mean_loss(self, labels):
        expected, mask = self.expected_and_mask(labels)
        mask = tf.cast(mask, tf.float32)
        count = tf.reduce_sum(mask)
        mean_absolute_error = tf.abs(
            (tf.log(expected + EPSILON) - self.prediction) * mask)
        loss = tf.reduce_sum(mean_absolute_error) / tf.maximum(count, EPSILON)
        return loss



class MultiClassificationObjective(ObjectiveBase):
    def __init__(self,
                 metadata_label,
                 name,
                 vessel_metadata,
                 loss_weight=1.0,
                 metrics='all'):
        super(MultiClassificationObjective, self).__init__(
            metadata_label, name, loss_weight, metrics)
        self.vessel_metadata = vessel_metadata
        self.classes = metadata.VESSEL_CLASS_DETAILED_NAMES
        self.num_classes = metadata.multihot_lookup_table.shape[-1]

        self.class_indices = {k[0]: i for (i, k) in enumerate(metadata.VESSEL_CATEGORIES)}