| 87 | FieldsOfExperts::FieldsOfExperts() : size_(0), num_filters_(0) {} |
| 88 | |
| 89 | bool FieldsOfExperts::LoadFromFile(const std::string& filename) { |
| 90 | std::ifstream foe_file(filename.c_str()); |
| 91 | foe_file >> size_; |
| 92 | foe_file >> num_filters_; |
| 93 | if (size_ < 0 || num_filters_ < 0) { |
| 94 | return false; |
| 95 | } |
| 96 | const int num_variables = NumVariables(); |
| 97 | |
| 98 | x_delta_indices_.resize(num_variables); |
| 99 | for (int i = 0; i < num_variables; ++i) { |
| 100 | foe_file >> x_delta_indices_[i]; |
| 101 | } |
| 102 | |
| 103 | y_delta_indices_.resize(NumVariables()); |
| 104 | for (int i = 0; i < num_variables; ++i) { |
| 105 | foe_file >> y_delta_indices_[i]; |
| 106 | } |
| 107 | |
| 108 | alpha_.resize(num_filters_); |
| 109 | for (int i = 0; i < num_filters_; ++i) { |
| 110 | foe_file >> alpha_[i]; |
| 111 | } |
| 112 | |
| 113 | filters_.resize(num_filters_); |
| 114 | for (int i = 0; i < num_filters_; ++i) { |
| 115 | filters_[i].resize(num_variables); |
| 116 | for (int j = 0; j < num_variables; ++j) { |
| 117 | foe_file >> filters_[i][j]; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // If any read failed, return failure. |
| 122 | if (!foe_file) { |
| 123 | size_ = 0; |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | // There cannot be anything else in the file. Try reading another number and |
| 128 | // return failure if that succeeded. |
| 129 | double temp; |
| 130 | foe_file >> temp; |
| 131 | if (foe_file) { |
| 132 | size_ = 0; |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | ceres::CostFunction* FieldsOfExperts::NewCostFunction(int alpha_index) const { |
| 140 | return new FieldsOfExpertsCost(filters_[alpha_index]); |