/// <summary>Retrieve best model (or model with the highest accuracy)</summary> /// <param name="models">List of models.</param> /// <param name="metric">Scoring metric to use for model selection.</param> /// <returns>Best Model.</returns> public static LearningModel Best(this IEnumerable <LearningModel> models, ScoringMetric metric = ScoringMetric.Accuracy) { return(models.OrderByDescending( m => { switch (metric) { case ScoringMetric.Accuracy: return m.Accuracy; case ScoringMetric.FScore: return m.Score.FScore; case ScoringMetric.Precision: return m.Score.Precision; case ScoringMetric.Recall: return m.Score.Recall; case ScoringMetric.RMSE: return m.Score.RMSE; case ScoringMetric.NormRMSE: return m.Score.NormRMSE; case ScoringMetric.AUC: return m.Score.AUC; case ScoringMetric.Fallout: return m.Score.Fallout; case ScoringMetric.Specificity: return m.Score.Specificity; default: return m.Accuracy; } }).FirstOrDefault()); }
/// <summary>Retrieve best model (or model with the highest accuracy)</summary> /// <param name="models">List of models.</param> /// <param name="metric">Scoring metric to use for model selection.</param> /// <returns>Best Model.</returns> public static LearningModel Best(this IEnumerable<LearningModel> models, ScoringMetric metric = ScoringMetric.Accuracy) { return models.OrderByDescending( m => { switch (metric) { case ScoringMetric.Accuracy: return m.Accuracy; case ScoringMetric.FScore: return m.Score.FScore; case ScoringMetric.Precision: return m.Score.Precision; case ScoringMetric.Recall: return m.Score.Recall; case ScoringMetric.RMSE: return m.Score.RMSE; case ScoringMetric.NormRMSE: return m.Score.NormRMSE; case ScoringMetric.AUC: return m.Score.AUC; case ScoringMetric.Fallout: return m.Score.Fallout; case ScoringMetric.Specificity: return m.Score.Specificity; default: return m.Accuracy; } }).FirstOrDefault(); }
// Sets up all paramters within the level to match the current difficulty selected void StartDifficulty() { // Difficulty implementations can be found on the spreadsheet if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.One)) { paddleSize = MovePaddle.PaddleSize.Large; numBalls = 1; ballSize = BallSpawner.BallSize.Large; ballSpeed = BallSpawner.BallSpeed.Slow; initAngle = BallSpawner.BallInitAngle.Shallow; hDirect = BallSpawner.BallHorizDirection.Left; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 0; obsSpeed = ObstacleSpawner.ObstacleSpeed.NULL; obstacleSpawnRate = 0; levelGeometryBasic.gameObject.SetActive(false); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Two)) { paddleSize = MovePaddle.PaddleSize.Large; numBalls = 1; ballSize = BallSpawner.BallSize.Large; ballSpeed = BallSpawner.BallSpeed.Slow; initAngle = BallSpawner.BallInitAngle.Shallow; hDirect = BallSpawner.BallHorizDirection.Left; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 0; obsSpeed = ObstacleSpawner.ObstacleSpeed.NULL; obstacleSpawnRate = 0; levelGeometryBasic.gameObject.SetActive(false); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Three)) { paddleSize = MovePaddle.PaddleSize.Large; numBalls = 1; ballSize = BallSpawner.BallSize.Medium; ballSpeed = BallSpawner.BallSpeed.Slow; initAngle = BallSpawner.BallInitAngle.Medium; hDirect = BallSpawner.BallHorizDirection.Left; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 0; obsSpeed = ObstacleSpawner.ObstacleSpeed.NULL; obstacleSpawnRate = 0; levelGeometryBasic.gameObject.SetActive(false); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Four)) { paddleSize = MovePaddle.PaddleSize.Large; numBalls = 1; ballSize = BallSpawner.BallSize.Medium; ballSpeed = BallSpawner.BallSpeed.Medium; initAngle = BallSpawner.BallInitAngle.Medium; hDirect = BallSpawner.BallHorizDirection.Left; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 0; obsSpeed = ObstacleSpawner.ObstacleSpeed.NULL; obstacleSpawnRate = 0; levelGeometryBasic.gameObject.SetActive(false); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Five)) { paddleSize = MovePaddle.PaddleSize.Medium; numBalls = 1; ballSize = BallSpawner.BallSize.Small; ballSpeed = BallSpawner.BallSpeed.Medium; initAngle = BallSpawner.BallInitAngle.Wide; hDirect = BallSpawner.BallHorizDirection.Left; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 0; obsSpeed = ObstacleSpawner.ObstacleSpeed.NULL; obstacleSpawnRate = 0; levelGeometryBasic.gameObject.SetActive(true); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Six)) { paddleSize = MovePaddle.PaddleSize.Medium; numBalls = 2; ballSize = BallSpawner.BallSize.Small; ballSpeed = BallSpawner.BallSpeed.Medium; initAngle = BallSpawner.BallInitAngle.Wide; hDirect = BallSpawner.BallHorizDirection.Random; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 0; obsSpeed = ObstacleSpawner.ObstacleSpeed.NULL; obstacleSpawnRate = 0; levelGeometryBasic.gameObject.SetActive(true); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Seven)) { paddleSize = MovePaddle.PaddleSize.Medium; numBalls = 2; ballSize = BallSpawner.BallSize.Large; ballSpeed = BallSpawner.BallSpeed.Medium; initAngle = BallSpawner.BallInitAngle.Random; hDirect = BallSpawner.BallHorizDirection.Random; scoringMetric = ScoringMetric.Bounce; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 2; obsSpeed = ObstacleSpawner.ObstacleSpeed.Slow; obstacleSpawnRate = 2.5f; levelGeometryBasic.gameObject.SetActive(true); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Eight)) { paddleSize = MovePaddle.PaddleSize.Small; numBalls = 2; ballSize = BallSpawner.BallSize.Medium; ballSpeed = BallSpawner.BallSpeed.Fast; initAngle = BallSpawner.BallInitAngle.Random; hDirect = BallSpawner.BallHorizDirection.Random; scoringMetric = ScoringMetric.BounceAndObstacle; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 4; obsSpeed = ObstacleSpawner.ObstacleSpeed.Slow; obstacleSpawnRate = 2.5f; levelGeometryBasic.gameObject.SetActive(true); levelGeometryAdv1.gameObject.SetActive(false); levelGeometryAdv2.gameObject.SetActive(false); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Nine)) { paddleSize = MovePaddle.PaddleSize.Small; numBalls = 2; ballSize = BallSpawner.BallSize.Medium; ballSpeed = BallSpawner.BallSpeed.Fast; initAngle = BallSpawner.BallInitAngle.Random; hDirect = BallSpawner.BallHorizDirection.Random; scoringMetric = ScoringMetric.BounceAndObstacle; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 6; obsSpeed = ObstacleSpawner.ObstacleSpeed.Fast; obstacleSpawnRate = 1.5f; levelGeometryBasic.gameObject.SetActive(true); levelGeometryAdv1.gameObject.SetActive(true); levelGeometryAdv2.gameObject.SetActive(true); } if (GlobalControl.Instance.difficulty.Equals(GlobalControl.Difficulty.Ten)) { paddleSize = MovePaddle.PaddleSize.Small; numBalls = 2; ballSize = BallSpawner.BallSize.Small; ballSpeed = BallSpawner.BallSpeed.Fast; initAngle = BallSpawner.BallInitAngle.Random; hDirect = BallSpawner.BallHorizDirection.Random; scoringMetric = ScoringMetric.BounceAndObstacle; obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs = 8; obsSpeed = ObstacleSpawner.ObstacleSpeed.Random; obstacleSpawnRate = 0.7f; levelGeometryBasic.gameObject.SetActive(true); levelGeometryAdv1.gameObject.SetActive(true); levelGeometryAdv2.gameObject.SetActive(true); } // Begins the level with the set-up parameters paddle.GetComponent <MovePaddle>().ResizePaddle(paddleSize); for (int i = 0; i < numBalls; i++) { ballSpawn.GetComponent <BallSpawner>().SpawnBall(ballSize, ballSpeed, initAngle, hDirect); } for (int i = 0; i < obstacleSpawn.GetComponent <ObstacleSpawner>().maxObs; i++) { obstacleSpawn.GetComponent <ObstacleSpawner>().SpawnObstacle(obsSpeed); } }