Skip to content

Commit

Permalink
show output regardless of exceeding limit
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 committed Feb 1, 2024
1 parent 94e5425 commit b89fd4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 40 deletions.
50 changes: 13 additions & 37 deletions ts/src/header-validator/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,9 +1221,10 @@ const testCases: TestCase[] = [
},

{
name: 'channel-capacity-default-event-custom-max',
name: 'channel-capacity-default-event',
json: `{"destination": "https://a.test"}`,
sourceType: SourceType.event,
noteInfoGain: true,
vsv: {
maxEventLevelChannelCapacityPerSource: {
[SourceType.event]: 0,
Expand All @@ -1234,67 +1235,42 @@ const testCases: TestCase[] = [
expectedErrors: [
{
path: [],
msg: 'exceeds max event-level channel capacity per event source (1.585 > 0.000)',
msg: 'information gain: 1.585 exceeds max event-level channel capacity per event source (0.000)',
},
],
},
{
name: 'channel-capacity-default-navigation-custom-max',
json: `{"destination": "https://a.test"}`,
sourceType: SourceType.navigation,
vsv: {
maxEventLevelChannelCapacityPerSource: {
[SourceType.event]: Infinity,
[SourceType.navigation]: 0,
},
maxSettableEventLevelEpsilon: 14,
},
expectedErrors: [
{
path: [],
msg: 'exceeds max event-level channel capacity per navigation source (11.462 > 0.000)',
},
],
},
{
name: 'channel-capacity-default-event-notes',
json: `{"destination": "https://a.test"}`,
sourceType: SourceType.event,
noteInfoGain: true,
vsv: {
maxSettableEventLevelEpsilon: 14,
},
expectedNotes: [
{
path: [],
msg: 'number of possible output states: 3',
},
{
path: [],
msg: 'information gain: 1.585',
},
{
path: [],
msg: 'randomized response rate: 0.00025%',
},
],
},
{
name: 'channel-capacity-default-navigation-notes',
name: 'channel-capacity-default-navigation',
json: `{"destination": "https://a.test"}`,
sourceType: SourceType.navigation,
noteInfoGain: true,
vsv: {
maxEventLevelChannelCapacityPerSource: {
[SourceType.event]: Infinity,
[SourceType.navigation]: 0,
},
maxSettableEventLevelEpsilon: 14,
},
expectedNotes: [
expectedErrors: [
{
path: [],
msg: 'number of possible output states: 2925',
msg: 'information gain: 11.462 exceeds max event-level channel capacity per navigation source (0.000)',
},
],
expectedNotes: [
{
path: [],
msg: 'information gain: 11.462',
msg: 'number of possible output states: 2925',
},
{
path: [],
Expand Down
11 changes: 8 additions & 3 deletions ts/src/header-validator/validate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,15 +839,20 @@ function channelCapacity(ctx: SourceContext, s: Source): void {
)

const max = ctx.vsv.maxEventLevelChannelCapacityPerSource[ctx.sourceType]
const infoGainMsg = `information gain: ${out.infoGain.toFixed(3)}`

if (out.infoGain > max) {
ctx.error(
`exceeds max event-level channel capacity per ${
`${infoGainMsg} exceeds max event-level channel capacity per ${
ctx.sourceType
} source (${out.infoGain.toFixed(3)} > ${max.toFixed(3)})`
} source (${max.toFixed(3)})`
)
} else if (ctx.noteInfoGain) {
ctx.note(infoGainMsg)
}

if (ctx.noteInfoGain) {
ctx.note(`number of possible output states: ${out.numStates}`)
ctx.note(`information gain: ${out.infoGain.toFixed(3)}`)
ctx.note(`randomized response rate: ${(100 * out.flipProb).toFixed(5)}%`)
}
}
Expand Down

0 comments on commit b89fd4d

Please sign in to comment.