Exemplo n.º 1
0
 def __init__(self, ci, cn, transf, max_iter, delta):
     Layer.__init__(self, ci, cn, cn, {'w': (cn, ci), 'b': cn})
     self.max_iter = max_iter
     self.delta = delta
     self.transf = transf
     self.outs = []
     if not hasattr(transf, 'out_minmax'):
         test = np.asfarry([-1e100, -100, -10, -1, 0, 1, 10, 100, 1e100])
         val = self.transf(test)
         self.out_minmax = np.array([val.min(), val.max()] * self.co)
     else:
         self.out_minmax = np.asfarray([transf.out_minmax] * self.co)
     self.initf = None
     self.s = np.zeros(self.cn)
Exemplo n.º 2
0
 def __init__(self, ci, cn, transf, max_iter, delta):
     Layer.__init__(self, ci, cn, cn, {'w': (cn, ci), 'b': cn})
     self.max_iter = max_iter
     self.delta = delta
     self.transf = transf
     self.outs = []
     if not hasattr(transf, 'out_minmax'):
         test = np.asfarry([-1e100, -100, -10, -1, 0, 1, 10, 100, 1e100])
         val = self.transf(test)
         self.out_minmax = np.array([val.min(), val.max()] * self.co)
     else:
         self.out_minmax = np.asfarray([transf.out_minmax] * self.co)
     self.initf = None
     self.s = np.zeros(self.cn)
Exemplo n.º 3
0
    def __init__(self, ci, cn, transf):

        Layer.__init__(self, ci, cn, cn, {'w':(cn, ci), 'b': cn})
        
        self.transf = transf
        if not hasattr(transf, 'out_minmax'):
            Inf = 1e100
            self.out_minmax = np.array([(self.transf(-Inf), self.transf(Inf))] * self.co)
        else:
            self.out_minmax = np.array([np.asfarray(transf.out_minmax)] * self.co)
        
        # default init function
        self.initf = init.initwb_reg
        self.s = np.zeros(self.cn)
Exemplo n.º 4
0
    def __init__(self, ci, cn, transf):

        Layer.__init__(self, ci, cn, cn, {'w': (cn, ci), 'b': cn})

        self.transf = transf
        if not hasattr(transf, 'out_minmax'):
            test = np.asfarry([-1e100, -100, -10, -1, 0, 1, 10, 100, 1e100])
            val = self.transf(test)
            self.out_minmax = np.array([val.min(), val.max()] * self.co)
        else:
            self.out_minmax = np.asfarray([transf.out_minmax] * self.co)
        # default init function
        self.initf = init.initwb_reg
        #self.initf = init.initwb_nw
        self.s = np.zeros(self.cn)
Exemplo n.º 5
0
    def __init__(self, ci, cn, transf):

        Layer.__init__(self, ci, cn, cn, {'w': (cn, ci), 'b': cn})

        self.transf = transf
        if not hasattr(transf, 'out_minmax'):
            test = np.asfarry([-1e100, -100, -10, -1, 0, 1, 10, 100, 1e100])
            val = self.transf(test)
            self.out_minmax = np.array([val.min(), val.max()] * self.co)
        else:
            self.out_minmax = np.asfarray([transf.out_minmax] * self.co)
        # default init function
        self.initf = init.initwb_reg
        #self.initf = init.initwb_nw
        self.s = np.zeros(self.cn)
Exemplo n.º 6
0
    def _compute(self, data, da, corpus, out, defaults):
        """
            INTERNAL: Applies the configured lambda to the dataset
            :param data: the dataset being processed
            :param da: extracted techniques from the dataset, sorted by
                dataset format
            :param corpus: master list of combined techniques and
                technique data
            :param out: baseline template for the new layer
            :param defaults: default values each technique should use if a
                field is missing
            :returns: a Layer object representing the resultant layer
        """
        composite = copy.deepcopy(corpus)
        if self._score is not None:
            for entry in composite:
                entry['score'] = self._applyOperation(da, entry, 'score',
                                                      self._score, defaults)

        if self._comment is not None:
            for entry in composite:
                entry['comment'] = self._applyOperation(
                    da, entry, 'comment', self._comment, defaults)

        if self._enabled is not None:
            for entry in composite:
                entry['enabled'] = self._applyOperation(
                    da, entry, 'enabled', self._enabled, defaults)

        if self._colors is not None:
            for entry in composite:
                entry['color'] = self._applyOperation(da, entry, 'color',
                                                      self._colors, defaults)

        if self._metadata is not None:
            for entry in composite:
                entry['metadata'] = self._applyOperation(
                    da, entry, 'metadata', self._metadata, defaults)

        processed = copy.deepcopy(out)
        processed['techniques'] = composite
        if self._name is not None:
            processed['name'] = self._applyOperation(data,
                                                     None,
                                                     'name',
                                                     self._name,
                                                     defaults,
                                                     glob='name')

        if self._desc is not None:
            processed['description'] = self._applyOperation(data,
                                                            None,
                                                            'description',
                                                            self._desc,
                                                            defaults,
                                                            glob='description')

        return Layer(processed)
Exemplo n.º 7
0
    def __init__(self, ci, cn, distf=None):
        Layer.__init__(self, ci, cn, cn, {'w': (cn, ci), 'conscience': cn})
        self.transf = trans.Competitive()
        self.initf = init.midpoint
        self.out_minmax[:] = np.array([self.transf.out_minmax] * cn)
        self.np['conscience'].fill(1.0)
        def euclidean(A, B):
            """
            Euclidean distance function.
            See scipi.spatial.distance.cdist()

            :Example:
                >>> import numpy as np
                >>> euclidean(np.array([0,0]), np.array([[0,1], [0, 5.5]])).tolist()
                [1.0, 5.5]

            """
            return np.sqrt(np.sum(np.square(A-B) ,axis=1))

        self.distf = euclidean
Exemplo n.º 8
0
 def __init__(self, ci, cn, distf=None):
     Layer.__init__(self, ci, cn, cn, {'w': (cn, ci), 'conscience': cn})
     self.transf = trans.Competitive()
     self.initf = init.midpoint
     self.out_minmax[:] = np.array([self.transf.out_minmax] * cn)
     self.np['conscience'].fill(1.0)
     def euclidean(A, B):
         """
         Euclidean distance function.
         See scipi.spatial.distance.cdist()
         
         :Example:
             >>> import numpy as np
             >>> euclidean(np.array([0,0]), np.array([[0,1], [0, 5.5]])).tolist()
             [1.0, 5.5]
             
         """
         return np.sqrt(np.sum(np.square(A-B) ,axis=1))
     
     self.distf = euclidean
Exemplo n.º 9
0
    parser.add_argument('-s','--source', choices=['taxii', 'local'], default='taxii', help='What source to utilize when building the matrix')
    parser.add_argument('--local', help='Path to the local resource if --source=local', default=None)
    parser.add_argument('-o','--output', nargs='+', help='Path(s) to the exported svg/xlsx file', required=True)
    parser.add_argument('-l', '--load_settings', help='[SVG Only] Path to a SVG configuration json to use when '
                                                      'rendering', default=None)
    parser.add_argument('-d', '--size', nargs=2, help='[SVG Only] X and Y size values (in inches) for SVG export (use '
                                                      '-l for other settings)', default=[8.5, 11], metavar=("WIDTH",
                                                                                                            "HEIGHT"))
    args = parser.parse_args()
    if len(args.output) != len(args.input):
        print('Mismatched number of output file paths to input file paths. Exiting...')

    for i in range(0, len(args.input)):
        entry = args.input[i]
        print('{}/{} - Beginning processing {}'.format(i + 1, len(args.input), entry))
        lay = Layer()
        try:
            lay.from_file(entry)
        except:
            print('Unable to load {}. Skipping...'.format(entry))
            continue
        if args.mode=='excel':
            if not args.output[i].endswith('.xlsx'):
                print('[ERROR] Unable to export {} as type: excel to {}'.format(entry, args.output[i]))
                continue
            exy = ToExcel(domain=lay.layer.domain, source=args.source, local=args.local)
            exy.to_xlsx(lay, filepath=args.output[i])
        else:
            if not args.output[i].endswith('.svg'):
                print('[ERROR] Unable to export {} as type: svg to {}'.format(entry, args.output[i]))
                continue
Exemplo n.º 10
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Export an ATT&CK Navigator layer as a svg image or excel file')
    parser.add_argument('-m',
                        '--mode',
                        choices=['svg', 'excel'],
                        required=True,
                        help='The form to export the layers in')
    parser.add_argument('input',
                        nargs='+',
                        help='Path(s) to the file to export')
    parser.add_argument('-s',
                        '--source',
                        choices=['taxii', 'local'],
                        default='taxii',
                        help='What source to utilize when building the matrix')
    parser.add_argument('--local',
                        help='Path to the local resource if --source=local',
                        default=None)
    parser.add_argument('-o',
                        '--output',
                        nargs='+',
                        help='Path(s) to the exported svg/xlsx file',
                        required=True)
    parser.add_argument(
        '-l',
        '--load_settings',
        help='[SVG Only] Path to a SVG configuration json to use when '
        'rendering',
        default=None)
    parser.add_argument(
        '-d',
        '--size',
        nargs=2,
        help='[SVG Only] X and Y size values (in inches) for SVG export (use '
        '-l for other settings)',
        default=[8.5, 11],
        metavar=("WIDTH", "HEIGHT"))
    args = parser.parse_args()
    if len(args.output) != len(args.input):
        print(
            'Mismatched number of output file paths to input file paths. Exiting...'
        )

    for i in range(0, len(args.input)):
        entry = args.input[i]
        print('{}/{} - Beginning processing {}'.format(i + 1, len(args.input),
                                                       entry))
        lay = Layer()
        try:
            lay.from_file(entry)
        except:
            print('Unable to load {}. Skipping...'.format(entry))
            continue
        if args.mode == 'excel':
            if not args.output[i].endswith('.xlsx'):
                print(
                    '[ERROR] Unable to export {} as type: excel to {}'.format(
                        entry, args.output[i]))
                continue
            exy = ToExcel(domain=lay.layer.domain,
                          source=args.source,
                          local=args.local)
            exy.to_xlsx(lay, filepath=args.output[i])
        else:
            if not args.output[i].endswith('.svg'):
                print('[ERROR] Unable to export {} as type: svg to {}'.format(
                    entry, args.output[i]))
                continue
            conf = SVGConfig()
            if args.load_settings:
                conf.load_from_file(args.load_settings)
            if len(args.size) == 2:
                conf.width = float(args.size[0])
                conf.height = float(args.size[1])
            svy = ToSvg(domain=lay.layer.domain,
                        source=args.source,
                        local=args.local,
                        config=conf)
            svy.to_svg(lay, filepath=args.output[i])
        print('{}/{} - Finished exporting {} to {}'.format(
            i + 1, len(args.input), entry, args.output[i]))
Exemplo n.º 11
0
 def __init__(self, ci, cb, transf, cbo=1, shift=1):
     
     Layer.__init__(self, ci, cn, cn, {'w': (cn, cb), 'b': cn})
     self.cb = cb
     self.shift = shift
     self.transf = transf
Exemplo n.º 12
0
import sys
sys.path.append("..")
from core import Layer, Tuple
from plotter import Plotter


layers = [
    
    Layer(name='conv1d_1', output_dim=Tuple(x=25, y=224), depth=64, activation='ReLu',
          output_dim_label='(224, 64)'),
    Layer(name='conv1d_2', output_dim=Tuple(x=25, y=224), depth=64, activation='ReLu', maxpool=True,
          output_dim_label='(224, 64)'),
    
    Layer(name='conv1d_3', output_dim=Tuple(x=25, y=112), depth=128, activation='ReLu',
          output_dim_label='(112, 128)'),
    Layer(name='conv1d_4', output_dim=Tuple(x=25, y=112), depth=128, activation='ReLu', maxpool=True,
          output_dim_label='(112, 128)'),
    
    Layer(name='conv1d_5', output_dim=Tuple(x=25, y=56), depth=256, activation='ReLu',
          output_dim_label='(56, 256)'),
    Layer(name='conv1d_6', output_dim=Tuple(x=25, y=56), depth=256, activation='ReLu', maxpool=True,
          output_dim_label='(56, 256)'),
    
    Layer(name='conv1d_7', output_dim=Tuple(x=25, y=28), depth=512, activation='ReLu',
          output_dim_label='(28, 512)'),
    Layer(name='conv1d_8', output_dim=Tuple(x=25, y=28), depth=512, activation='ReLu',
          output_dim_label='(28, 512)'),
    Layer(name='conv1d_9', output_dim=Tuple(x=25, y=28), depth=512, activation='ReLu', maxpool=True,
          output_dim_label='(28, 512)'),
    
    Layer(name='conv1d_10', output_dim=Tuple(x=25, y=14), depth=512, activation='ReLu',
Exemplo n.º 13
0
import sys
sys.path.append("..")

from core import Layer, Tuple
from plotter import Plotter


layers = [
    Layer(name='input', output_dim=Tuple(25, 198), depth=2,
          output_dim_label='(S, 2)'),
    Layer(name='conv1d_1', output_dim=Tuple(25, 198), depth=128, activation='ReLu',
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_2', output_dim=Tuple(25, 198), depth=128, activation='ReLu', maxpool=True,
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_3', output_dim=Tuple(25, 99), depth=128, activation='ReLu',
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_4', output_dim=Tuple(25, 99), depth=128, activation='ReLu', maxpool=True,
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_5', output_dim=Tuple(25, 49), depth=128, activation='ReLu',
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_6', output_dim=Tuple(25, 49), depth=128, activation='ReLu', maxpool=True,
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_7', output_dim=Tuple(25, 24), depth=128, activation='ReLu',
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_8', output_dim=Tuple(25, 24), depth=128, activation='ReLu', maxpool=True,
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_9', output_dim=Tuple(25, 12), depth=128, activation='ReLu',
          output_dim_label='(S, 128)'),
    Layer(name='conv1d_10', output_dim=Tuple(25, 12), depth=128, activation='ReLu', flatten=True,
          output_dim_label='(S, 128)'),
    Layer(name='dense_1', output_dim=Tuple(25, 1), depth=256, activation='ReLu',
Exemplo n.º 14
0
import sys
sys.path.append("..")

from core import Layer, Tuple
from plotter import Plotter

layers = [
    Layer(name='conv1d_1',
          output_dim=Tuple(55, 55),
          depth=90,
          maxpool=True,
          activation='ReLu',
          output_dim_label='(55, 55, 96)'),
    Layer(name='conv1d_2',
          output_dim=Tuple(27, 27),
          depth=200,
          maxpool=True,
          activation='ReLu',
          output_dim_label='(27, 27, 256)'),
    Layer(name='conv1d_3',
          output_dim=Tuple(13, 13),
          depth=300,
          activation='ReLu',
          output_dim_label='(13, 13, 384)'),
    Layer(name='conv1d_4',
          output_dim=Tuple(13, 13),
          depth=300,
          activation='ReLu',
          output_dim_label='(13, 13, 384)'),
    Layer(name='conv1d_5',
          output_dim=Tuple(13, 13),