Skip to content

Commit ce1c3d5

Browse files
To summarize the changes:
1. For the Fired class: - Updated the class to properly inherit from Step - Fixed the createQueueKey method to use FiredQueueKey - Implemented the updateNet method to handle numeric conversion without ApproximateComparisonValueUtil - Fixed the toString method to properly format doubles - Added proper const qualifiers to methods 2. For the Save class: - Updated the class to properly inherit from ElementStep - Fixed the process method to properly cast the Element to Neuron - Added proper const qualifiers to methods
1 parent 41bab99 commit ce1c3d5

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

include/network/activation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Activation : public Obj, public Element, public ModelProvider {
5151
Timestamp getFired();
5252
void setFired();
5353
void setFired(Timestamp f);
54-
void updateFiredStep(FieldOutput* net);
54+
void updateFiredStep(Field* net);
5555
Queue* getQueue();
5656
Neuron* getNeuron();
5757
Document* getDocument();

include/network/fired.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
#include "network/activation.h"
66
#include "network/phase.h"
77
#include "network/queue.h"
8+
#include "network/timestamp.h"
89
#include <string>
910

10-
class Fired : public Step<Activation> {
11+
class Fired : public Step {
1112
public:
1213
Fired(Activation* act);
14+
virtual ~Fired() = default;
1315

1416
void createQueueKey(Timestamp timestamp, int round) override;
1517
void process() override;
1618
void updateNet(double net);
17-
Phase getPhase() override;
18-
Activation* getElement() override;
19-
Queue* getQueue() override;
20-
std::string toString() override;
19+
Phase getPhase() const override;
20+
Activation* getElement();
21+
Queue* getQueue() const override;
22+
std::string toString() const override;
23+
bool isQueued() const;
2124

2225
private:
2326
Activation* act;

include/network/save.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
#include "network/element_step.h"
55
#include "network/neuron.h"
66
#include "network/phase.h"
7+
#include "fields/step.h"
78

8-
class Save : public ElementStep<Neuron> {
9+
class Save : public ElementStep {
910
public:
1011
static void add(Neuron* n);
1112

1213
Save(Neuron* n);
14+
virtual ~Save() = default;
1315

14-
Phase getPhase() override;
16+
Phase getPhase() const override;
1517
void process() override;
1618
};
1719

src/network/fired.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#include "network/fired.h"
22
#include "network/activation.h"
3-
#include "network/field_queue_key.h"
4-
#include "network/approximate_comparison_value_util.h"
5-
#include "network/string_utils.h"
3+
#include "fields/queue_key.h"
4+
#include "network/fired_queue_key.h"
5+
#include <string>
6+
#include <sstream>
7+
#include <iomanip>
68

7-
Fired::Fired(Activation* act) : act(act), net(0.0), sortValue(0) {}
9+
Fired::Fired(Activation* act) : Step(), act(act), net(0.0), sortValue(0) {}
810

911
void Fired::createQueueKey(Timestamp timestamp, int round) {
10-
queueKey = new FieldQueueKey(round, getPhase(), sortValue, timestamp);
12+
queueKey = new FiredQueueKey(round, getPhase(), getElement(), timestamp);
1113
}
1214

1315
void Fired::process() {
16+
Activation* act = getElement();
17+
1418
act->setFired();
1519

1620
// Only once the activation is fired, will it be visible to other neurons.
@@ -23,21 +27,30 @@ void Fired::process() {
2327

2428
void Fired::updateNet(double net) {
2529
this->net = net;
26-
sortValue = ApproximateComparisonValueUtil::convert(net);
30+
// Simple conversion to int for sort value (handles approximate comparison)
31+
// The original Java uses ApproximateComparisonValueUtil
32+
sortValue = static_cast<int>(net * 1000.0); // Scale to preserve 3 decimals of precision
2733
}
2834

29-
Phase Fired::getPhase() {
35+
Phase Fired::getPhase() const {
3036
return Phase::FIRED;
3137
}
3238

3339
Activation* Fired::getElement() {
3440
return act;
3541
}
3642

37-
Queue* Fired::getQueue() {
43+
Queue* Fired::getQueue() const {
3844
return act->getDocument();
3945
}
4046

41-
std::string Fired::toString() {
42-
return std::to_string(getElement()) + " net:" + StringUtils::doubleToString(net);
47+
bool Fired::isQueued() const {
48+
return isQueued;
49+
}
50+
51+
std::string Fired::toString() const {
52+
// Format the double with fixed precision (3 decimal places)
53+
std::ostringstream ss;
54+
ss << std::fixed << std::setprecision(3) << net;
55+
return getElement()->toString() + " net:" + ss.str();
4356
}

src/network/save.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#include "network/save.h"
2+
#include "fields/step.h"
23

34
void Save::add(Neuron* n) {
45
Step::add(new Save(n));
56
}
67

78
Save::Save(Neuron* n) : ElementStep(n) {}
89

9-
Phase Save::getPhase() {
10+
Phase Save::getPhase() const {
1011
return Phase::SAVE;
1112
}
1213

1314
void Save::process() {
14-
getElement()->save();
15+
// Cast the Element* to Neuron* before calling save()
16+
Neuron* neuron = static_cast<Neuron*>(getElement());
17+
neuron->save();
1518
}

0 commit comments

Comments
 (0)