C++ API Reference for Intel® Data Analytics Acceleration Library 2018 Update 1

neural_networks_prediction_topology.h
1 /* file: neural_networks_prediction_topology.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 #ifndef __NEURAL_NETWORKS_PREDICTION_TOPOLOGY_H__
43 #define __NEURAL_NETWORKS_PREDICTION_TOPOLOGY_H__
44 
45 #include "algorithms/neural_networks/layers/layer_forward_descriptor.h"
46 #include "algorithms/neural_networks/neural_networks_training_topology.h"
47 
48 namespace daal
49 {
50 namespace algorithms
51 {
52 namespace neural_networks
53 {
54 namespace prediction
55 {
56 namespace interface1
57 {
58 
68 class Topology: public Base
69 {
70 protected:
71  typedef services::Collection<layers::forward::LayerDescriptor> Descriptors;
72 
73 public:
75  Topology() {}
76 
81  Topology(const training::Topology &t) : _config(t.size())
82  {
83  for(size_t i = 0; i < _config.size(); ++i)
84  {
85  const layers::LayerDescriptor& desc = t[i];
86  layers::forward::LayerIfacePtr predictionLayer = desc.layer()->forwardLayer->getLayerForPrediction();
87  _config[i] = layers::forward::LayerDescriptor(i, predictionLayer, desc.nextLayers());
88  predictionLayer->getLayerParameter()->predictionStage = true;
89  }
90  }
91 
96  Topology(const Topology &t) : _config(t.size())
97  {
98  for(size_t i = 0; i < t.size(); i++)
99  {
100  _config[i] = layers::forward::LayerDescriptor(i, t[i].layer(), t[i].nextLayers());
101  }
102  }
103 
108  size_t size() const { return _config.size(); }
109 
115  size_t push_back(const layers::forward::LayerIfacePtr &layer)
116  {
117  size_t id = _config.size();
118  _config.push_back(layers::forward::LayerDescriptor(id, layer));
119  return id;
120  }
121 
127  size_t add(const layers::forward::LayerIfacePtr &layer)
128  {
129  return push_back(layer);
130  }
131 
138  size_t add(const Topology &topologyBlock, size_t &startIndex)
139  {
140  size_t size = _config.size();
141  startIndex = size;
142 
143  size_t id = 0;
144  for(size_t i = 0; i < topologyBlock.size(); i++)
145  {
146  id = push_back(topologyBlock[i].layer());
147  const layers::NextLayers& nextLayers = topologyBlock[i].nextLayers();
148  for(size_t j = 0; j < nextLayers.size(); j++)
149  {
150  addNext(i + size, nextLayers[j] + size);
151  }
152  }
153  return id;
154  }
155 
161  services::Status clear()
162  {
163  _config.clear();
164  return services::Status();
165  }
166 
172  layers::forward::LayerDescriptor& operator [] (size_t index) { return _config[index]; }
173 
179  const layers::forward::LayerDescriptor& operator [] (size_t index) const { return _config[index]; }
180 
186  layers::forward::LayerDescriptor& get(size_t index) { return _config[index]; }
187 
193  const layers::forward::LayerDescriptor& get(size_t index) const { return _config[index]; }
194 
195 
204  services::Status addNext(size_t index, size_t next)
205  {
206  _config[index].addNext(next);
207  return services::Status();
208  }
209 
210 protected:
211  Descriptors _config;
212 };
213 
214 typedef services::SharedPtr<Topology> TopologyPtr;
216 }
217 
218 using interface1::Topology;
219 using interface1::TopologyPtr;
220 }
221 }
222 }
223 }
224 
225 #endif
daal::algorithms::neural_networks::prediction::interface1::Topology::Topology
Topology(const training::Topology &t)
Definition: neural_networks_prediction_topology.h:81
daal
Definition: algorithm_base_common.h:57
daal::algorithms::neural_networks::prediction::interface1::Topology
Class defining a neural network topology - a set of layers and connection between them - on the predi...
Definition: neural_networks_prediction_topology.h:68
daal::algorithms::neural_networks::prediction::interface1::Topology::clear
services::Status clear()
Definition: neural_networks_prediction_topology.h:161
daal::algorithms::neural_networks::prediction::interface1::Topology::size
size_t size() const
Definition: neural_networks_prediction_topology.h:108
daal::algorithms::neural_networks::prediction::interface1::Topology::Topology
Topology(const Topology &t)
Definition: neural_networks_prediction_topology.h:96
daal::algorithms::neural_networks::prediction::interface1::Topology::push_back
size_t push_back(const layers::forward::LayerIfacePtr &layer)
Definition: neural_networks_prediction_topology.h:115
daal::algorithms::neural_networks::prediction::interface1::Topology::operator[]
layers::forward::LayerDescriptor & operator[](size_t index)
Definition: neural_networks_prediction_topology.h:172
daal::algorithms::neural_networks::prediction::interface1::Topology::Topology
Topology()
Definition: neural_networks_prediction_topology.h:75
daal::algorithms::neural_networks::prediction::interface1::Topology::addNext
services::Status addNext(size_t index, size_t next)
Definition: neural_networks_prediction_topology.h:204
daal::algorithms::classifier::prediction::prediction
Definition: classifier_predict_types.h:102
daal::algorithms::neural_networks::prediction::interface1::Topology::add
size_t add(const Topology &topologyBlock, size_t &startIndex)
Definition: neural_networks_prediction_topology.h:138
daal::algorithms::neural_networks::prediction::interface1::Topology::add
size_t add(const layers::forward::LayerIfacePtr &layer)
Definition: neural_networks_prediction_topology.h:127
daal::Base
Base class for Intel(R) Data Analytics Acceleration Library objects
Definition: base.h:65

For more complete information about compiler optimizations, see our Optimization Notice.