Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienVig committed Feb 8, 2024
1 parent 998f6db commit 46dd452
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions discojs/discojs-core/src/validation/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,36 @@ export class Validator {

let hits = 0
await data.preprocess().dataset.batch(batchSize)
.forEachAsync((e) => {
if (typeof e === 'object' && 'xs' in e && 'ys' in e) {
const xs = e.xs as tf.Tensor
.forEachAsync((e) => {
if (typeof e === 'object' && 'xs' in e && 'ys' in e) {
const xs = e.xs as tf.Tensor

const ys = this.getLabel(e.ys as tf.Tensor)
const pred = this.getLabel(model.predict(xs, { batchSize }) as tf.Tensor)
const ys = this.getLabel(e.ys as tf.Tensor)
const pred = this.getLabel(model.predict(xs, { batchSize }) as tf.Tensor)

const currentFeatures = xs.arraySync()
const currentFeatures = xs.arraySync()

if (Array.isArray(currentFeatures)) {
features = features.concat(currentFeatures)
} else {
throw new TypeError('features array is not correct')
}
if (Array.isArray(currentFeatures)) {
features = features.concat(currentFeatures)
} else {
throw new TypeError('features array is not correct')
}

groundTruth.push(...Array.from(ys))
predictions.push(...Array.from(pred))
groundTruth.push(...Array.from(ys))
predictions.push(...Array.from(pred))

this.size += xs.shape[0]
this.size += xs.shape[0]

hits += List(pred).zip(List(ys)).filter(([p, y]) => p === y).size
hits += List(pred).zip(List(ys)).filter(([p, y]) => p === y).size

// TODO: Confusion Matrix stats
// TODO: Confusion Matrix stats

const currentAccuracy = hits / this.size
this.graphInformant.updateAccuracy(currentAccuracy)
} else {
throw new Error('missing feature/label in dataset')
}
})
const currentAccuracy = hits / this.size
this.graphInformant.updateAccuracy(currentAccuracy)
} else {
throw new Error('missing feature/label in dataset')
}
})
this.logger.success(`Obtained validation accuracy of ${this.accuracy}`)
this.logger.success(`Visited ${this.visitedSamples} samples`)

Expand Down Expand Up @@ -105,20 +105,20 @@ export class Validator {

await data.preprocess().dataset.batch(batchSize)
.forEachAsync(e => {
const xs = e as tf.Tensor
const currentFeatures = xs.arraySync()

if (Array.isArray(currentFeatures)) {
features = features.concat(currentFeatures)
} else {
throw new TypeError('features array is not correct')
}
const xs = e as tf.Tensor
const currentFeatures = xs.arraySync()

const pred = this.getLabel(model.predict(xs, { batchSize }) as tf.Tensor)
predictions.push(...Array.from(pred))
if (Array.isArray(currentFeatures)) {
features = features.concat(currentFeatures)
} else {
throw new TypeError('features array is not correct')
}

const pred = this.getLabel(model.predict(xs, { batchSize }) as tf.Tensor)
predictions.push(...Array.from(pred))
})

return (List(features).zip(List(predictions)) as List<[Features, number]>)
return List(features).zip(List(predictions))
.map(([f, p]) => ({ features: f, pred: p }))
.toArray()
}
Expand Down

0 comments on commit 46dd452

Please sign in to comment.