Re: continue Method

本文深入探讨了Java中的控制流程语句,包括break、continue和return的使用场景及注意事项,通过实例展示了如何利用这些语句优化循环逻辑。此外,文章还介绍了方法的定义与调用,展示了如何通过方法实现特定功能,如求和、比较大小和查找数组最大值,为读者提供了实用的编程技巧。

“叮——”
“您的强化已经送到目的地,您被强化了,快送。。。”
简单粗暴的break:

class Demo1_Break {
public static void main(String[] args) {
            //break;写在这报错,break只能用在循环和switch语句中
	for (int x = 1;x <= 10 ;x++ ) {
		if (x == 4) {
			break;							//跳出循环
		}
		System.out.println("x = " + x);
		}
	}
}

呆萌可爱的continue:

class Demo2_Continue {
public static void main(String[] args) {
	for (int x = 1;x <= 10 ;x++ ) {
		if (x == 4) {
			continue;							//终止本次循环,继续下次循环
		}
		System.out.println("x = " + x);
		}
	}
}

捎带上的return:

class Demo3_Return {
public static void main(String[] args) {
	for (int i = 1;i <= 10 ;i++ ) {
		if (i == 4) {				
			//break;						//停止循环
			return;							//返回的意思,用来返回方法
		}
	}

	System.out.println("循环结束了");
	}
}

某种意义上的三等分,虽然不会出现党争,不过对于主角的加成是可以暂时打败魔王的了,捎带的复活效果不止救活了勇者,还给魔王加了一层复活甲状态。。。逻辑老师,我成功了。
中场幕间
并没有打败魔王,勇者小队开始了构思新的方法,对,就是Method。就算是剑士也得学点M魔法,于是乎

class Demo4_Sum {
public static void main(String[] args) {
	/*int a = 10;
	int b = 20;
	int sum = a + b;
	System.out.println(sum);

	int c = 30;
	int d = 40;
	int sum2 = c + d;
	System.out.println(sum2);*/

	int sum = add(10,20);
	System.out.println(sum);

	//add(30,40);						//有返回值方法的单独调用,没有意义
	System.out.println(add(30,40));		//这样调用是可以,but如果需要用这个结果不推荐这样调用

	//盘子 = 炒菜(地沟油,苏丹红,镉大米,烂白菜);
}	
public static int add(int a,int b) {			//int a = 10,int b = 20
	int sum = a + b;
	return sum;								//如果有返回值必须用return语句带回
}

/*
盘子 炒菜(油,调料,米,菜) {
	炒菜的动作
	return 一盘菜;
	}
*/

}

先来一道菜补补体力,然后是比较魔力:

import java.util.Scanner;
class Test1_Method {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);				//创建键盘录入对象
	System.out.println("请输入第一个整数:");
	int x = sc.nextInt();								//将键盘录入的整数存储在x中
	System.out.println("请输入第二个整数:");
	int y = sc.nextInt();								//将键盘录入的整数存储在y中

	//int max = getMax(x,y);
	//System.out.println(max);

	boolean b = isEquals(x,y);
	System.out.println(b);
}

/*
返回连个整数的较大值
1,明确返回值类型 int
2,明确参数列表 int a,int b
*/
public static int getMax(int a,int b) {
	return a > b ? a : b;
}

/*
判断两个整数是否相等
1,明确返回值类型 boolean
2,明确参数列表 int a,int b
*/
public static boolean isEquals(int a,int b) {		//isEquals 是否相等
	return a == b;
	}
}

胜出者将会赢取公主。。。不对,这个不够正式,应该摆个擂台,数组已经饥渴难耐了。

class Demo5_Array {
public static void main(String[] args) {
	int[] arr = {33,77,22,44,55};

              int   max =  da (arr);
         System.out.println(max);

}

/*
获取数组中最大值
1,返回值类型int
2,参数列表int[] arr
*/

public static int da(int[] arr) {
	int max = arr[0];
	for (int i = 1;i < arr.length ;i++ ) {			//从数组的第二个元素开始遍历
		if (max < arr[i]) {							//如果max记录的值小于的数组中的元素
			max = arr[i];							//max记录住较大的
		}
	}

	return max;
	}
}

胜出者是魔王!!!
for ps:每日一词
念奴娇·屋破犹待客

青山无悔,被初冬雪染,几曾白首。笼统一番云掩日,北雁难飞还走。香欲清烟,兽炉添乱,风虎云龙斗。江山坐看,几多名俪佳句。

我笑行客相逢,举杯邀月,却憾明轮无。起舞、和烟轻树下,犹可诗词歌赋。人不应知,几多烦事,何苦横眉皱。破屋笼中,落初栖凤凰羽。

import os import numpy as np import matplotlib.pyplot as plt import re from matplotlib.ticker import MaxNLocator from scipy.stats import linregress import matplotlib.patches as mpatches # 解决中文显示问题 plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'WenQuanYi Micro Hei'] plt.rcParams['axes.unicode_minus'] = False def natural_sort_key(s): """自然排序算法:确保文件名按数字顺序排列""" return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', s)] def find_stable_intervals(counts, method='极', min_window=300, max_window=2000, threshold=0.5, merge_gap=300, min_length=500, return_base=False): """ 改进版稳定区间检测:支持三种不同指标 :param counts: 预测框数量列表(原始数据) :param method: 检测方法 ('std', 'zscore', 'slope') :param min_window: 最小窗口尺寸 :param max_window: 最大窗口尺寸 :param threshold: 阈值(基于整体统计量) :param merge_gap: 相邻区间合并的最大间隔 :param min_length: 最小有效区间长度 :param return_base: 是否返回基础区间(合并前) :return: 优化后的稳定区间列表 """ n = len(counts) if n == 0: return [] if not return_base else ([], [], []) # 计算整体统计量 total_mean = np.mean(counts) total_std = np.std(counts) # 1. 改进的窗口扩展检测机制 base_intervals = [] i = 0 # 当前检测起始点 while i < n: # 跳过已检测区域 if base_intervals and i <= base_intervals[-1][1]: i = base_intervals[-1][1] + 1 continue # 确保有足够的数据点 if i + min_window > n: break window_size = min_window stable_found = False # 检查当前窗口是否稳定 window = counts[i:i + window_size] if len(window) < 2: i += 1 continue # 检测稳定性 if method == 'std': std_dev = np.std(window) stable = std_dev < threshold elif method == 'zscore_avg': mean_val = np.mean(window) std_val = np.std(window) if std_val > 0: z_scores = np.abs((window - mean_val) / std_val) avg_zscore = np.mean(z_scores) stable = avg_zscore < threshold else: stable = True # 所有值相同 elif method == 'slope': x = np.arange(len(window)) slope, _, _, _, _ = linregress(x, window) stable = abs(slope) < threshold # 如果稳定,则尝试扩展窗口 if stable: stable_found = True start_idx = i end_idx = i + window_size - 1 # 尝试扩展窗口 while end_idx < n - 1 and window_size < max_window: # 扩展一个点 window_size += 1 new_end = i + window_size - 1 if new_end >= n: break # 获取新窗口 window = counts[i:new_end + 1] if len(window) < 2: break # 检测新窗口的稳定性 if method == 'std': std_dev = np.std(window) current_stable = std_dev < threshold elif method == 'zscore_avg': mean_val = np.mean(window) std_val = np.std(window) if std_val > 0: z_scores = np.abs((window - mean_val) / std_val) avg_zscore = np.mean(z_scores) current_stable = avg_zscore < threshold else: current_stable = True elif method == 'slope': x = np.arange(len(window)) slope, _, _, _, _ = linregress(x, window) current_stable = abs(slope) < threshold # 如果仍然稳定,更新结束索引 if current_stable: end_idx = new_end else: # 不稳定,回退到上一个稳定点 window_size -= 1 break # 添加找到的稳定区间 base_intervals.append((start_idx, end_idx)) i = end_idx + 1 # 从结束点后开始新检测 else: # 不稳定,移动到下一个点 i += 1 # 如果没有检测到任何区间,直接返回 if not base_intervals: if return_base: return [], [], [] return [] # 2. 合并相邻平稳段 base_intervals.sort(key=lambda x: x[0]) # 确保按起始索引排序 merged_intervals = [] current_start, current_end = base_intervals[0] for start, end in base_intervals[1:]: if start - current_end <= merge_gap: # 间隔小于合并阈值 current_end = max(current_end, end) # 扩展当前区间 else: merged_intervals.append((current_start, current_end)) current_start, current_end = start, end merged_intervals.append((current_start, current_end)) # 3. 过滤短时伪平稳段 final_intervals = [ (start, end) for start, end in merged_intervals if (end - start + 1) >= min_length # 区间长度包含两端点 ] if return_base: return base_intervals, merged_intervals, final_intervals return final_intervals def plot_box_count_trend(file_list, box_counts, stable_intervals, output_path, title_suffix="", method_name="标准差", is_base=False): """ 绘制预测框数量变化趋势图并标记稳定区间 :param is_base: 是否为基本区间图(合并前) """ plt.figure(figsize=(20, 10)) # 绘制整体趋势(原始数据) plt.plot(file_list, box_counts, 'b-', linewidth=1.5, label='预测框数量') # 计算全局最小值和最大值(用于颜色块填充) global_min = min(box_counts) - 0.5 global_max = max(box_counts) + 0.5 # 根据方法名称设置颜色(与合并图保持一致) method_colors = { '标准差方法': 'green', 'Z-score方法': 'purple', '趋势斜率方法': 'orange' } # 获取当前方法的颜色 fill_color = method_colors.get(method_name, 'green') # 默认绿色 # 标记稳定区间 for i, (start, end) in enumerate(stable_intervals): interval_files = file_list[start:end + 1] if not interval_files: continue # 绘制稳定区间 - 使用对应方法的颜色 if is_base: # 基本区间图:颜色块只覆盖数据范围(避免叠加) interval_counts = box_counts[start:end + 1] min_count = min(interval_counts) if interval_counts else 0 max_count = max(interval_counts) if interval_counts else 0 plt.fill_between(interval_files, min_count, max_count, color=fill_color, alpha=0.3, zorder=0) else: # 稳定区间图:颜色块顶到图表边缘 plt.fill_between(interval_files, global_min, global_max, color=fill_color, alpha=0.3, zorder=0) # 如果是基本区间图(合并前),不添加标注,避免过多标注 if not is_base: # 添加区间标注 interval_counts = box_counts[start:end + 1] if interval_counts: avg_count = np.mean(interval_counts) std_dev = np.std(interval_counts) mid_idx = start + (end - start) // 2 if mid_idx < len(file_list): plt.annotate(f"区间{i + 1}: {start + 1}-{end + 1}\n均值: {avg_count:.1f}±{std_dev:.1f}", (file_list[mid_idx], avg_count), xytext=(0, 20), textcoords='offset points', ha='center', fontsize=10, bbox=dict(boxstyle="round,pad=0.3", fc="yellow", alpha=0.7), zorder=10) # 设置图表属性 plot_type = "基础区间" if is_base else "稳定区间" plt.title(f'预测框数量变化趋势 - {method_name}{title_suffix} ({plot_type})', fontsize=18) plt.xlabel('图像文件名', fontsize=14) plt.ylabel('预测框数量', fontsize=14) plt.xticks(rotation=90, fontsize=7) plt.grid(True, linestyle='--', alpha=0.6) # 已删除图例 plt.gca().xaxis.set_major_locator(MaxNLocator(20)) plt.tight_layout() plt.savefig(output_path, dpi=150, bbox_inches='tight') plt.close() def plot_combined_intervals(file_list, box_counts, intervals_std, intervals_zscore, intervals_slope, output_path): """ 绘制三种方法检测结果的合并图 """ plt.figure(figsize=(20, 10)) # 绘制整体趋势(原始数据) plt.plot(file_list, box_counts, 'b-', linewidth=1.5, label='预测框数量') # 计算全局最小值和最大值(用于颜色块填充) global_min = min(box_counts) - 0.5 global_max = max(box_counts) + 0.5 # 为每种方法定义不同的颜色和标签 method_colors = { '标准差方法': ('green', '标准差区间'), 'Z-score方法': ('purple', 'Z-score区间'), '趋势斜率方法': ('orange', '趋势斜率区间') } # 绘制标准差方法的区间 for i, (start, end) in enumerate(intervals_std): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['标准差方法'][0], alpha=0.3, zorder=0) # 绘制Z-score方法的区间 for i, (start, end) in enumerate(intervals_zscore): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['Z-score方法'][0], alpha=0.3, zorder=0) # 绘制趋势斜率方法的区间 for i, (start, end) in enumerate(intervals_slope): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['趋势斜率方法'][0], alpha=0.3, zorder=0) # 设置图表属性 plt.title('预测框数量变化趋势及稳定区间分析 - 三种方法合并', fontsize=18) plt.xlabel('图像文件名', fontsize=14) plt.ylabel('预测框数量', fontsize=14) plt.xticks(rotation=90, fontsize=7) plt.grid(True, linestyle='--', alpha=0.6) # 已删除图例 plt.gca().xaxis.set_major_locator(MaxNLocator(20)) plt.tight_layout() plt.savefig(output_path, dpi=150, bbox_inches='tight') plt.close() def plot_combined_base_intervals(file_list, box_counts, base_std, base_zscore, base_slope, output_path): """ 绘制三种方法基础区间的三合一图 :param file_list: 文件名列表 :param box_counts: 原始预测框数量列表 :param base_std: 标准差方法的基础区间 :param base_zscore: Z-score方法的基础区间 :param base_slope: 趋势斜率方法的基础极 :param output_path: 输出图片路径 """ plt.figure(figsize=(20, 10)) # 绘制整体趋势(原始数据) plt.plot(file_list, box_counts, 'b-', linewidth=1.5, label='预测框数量') # 计算全局最小值和最大值(用于颜色块填充) global_min = min(box_counts) - 0.5 global_max = max(box_counts) + 0.5 # 定义每种方法的颜色和标签 method_colors = { '标准差方法': ('green', '标准差基础区间'), 'Z-score方法': ('purple', 'Z-score基础区间'), '趋势斜率方法': ('orange', '趋势斜率基础区间') } # 绘制标准差方法的基础区间 for i, (start, end) in enumerate(base_std): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['标准差方法'][0], alpha=0.2, zorder=0) # 绘制Z-score方法的基础区间 for i, (start, end) in enumerate(base_zscore): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['Z-score方法'][0], alpha=0.2, zorder=0) # 绘制趋势斜率方法的基础区间 for i, (start, end) in enumerate(base_slope): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['趋势斜率方法'][0], alpha=0.2, zorder=0) # 设置图表属性 plt.title('预测框数量变化趋势及基础稳定区间分析 - 三种方法合并', fontsize=18) plt.xlabel('图像文件名', fontsize=14) plt.ylabel('预测框数量', fontsize=14) plt.xticks(rotation=90, fontsize=7) plt.grid(True, linestyle='--', alpha=0.6) # 已删除图例 plt.gca().xaxis.set_major_locator(MaxNLocator(20)) plt.tight_layout() plt.savefig(output_path, dpi=150, bbox_inches='tight') plt.close() def plot_std_zscore_base_intervals(file_list, box_counts, base_std, base_zscore, output_path): """ 绘制标准差和Z-score基础稳定区间的二合一图 :param file_list: 文件名列表 :param box_counts: 原始预测框数量列表 :param base_std: 标准差方法的基础区间 :param base_zscore: Z-score方法的基础区间 :param output_path: 输出图片路径 """ plt.figure(figsize=(20, 10)) # 绘制整体趋势(原始数据) plt.plot(file_list, box_counts, 'b-', linewidth=1.5, label='预测框数量') # 计算全局最小值和最大值(用于颜色块填充) global_min = min(box_counts) - 0.5 global_max = max(box_counts) + 0.5 # 定义每种方法的颜色和标签 method_colors = { '标准差方法': ('green', '标准差基础区间'), 'Z-score方法': ('purple', 'Z-score基础区间') } # 绘制标准差方法的基础区间 for i, (start, end) in enumerate(base_std): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['标准差方法'][0], alpha=0.2, zorder=0) # 绘制Z-score方法的基础区间 for i, (start, end) in enumerate(base_zscore): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['Z-score方法'][0], alpha=0.2, zorder=0) # 设置图表属性 plt.title('预测框数量变化趋势及基础稳定区间分析 - 标准差与Z-score方法', fontsize=18) plt.xlabel('图像文件名', fontsize=14) plt.ylabel('预测框数量', fontsize=14) plt.xticks(rotation=90, fontsize=7) plt.grid(True, linestyle='--', alpha=0.6) # 已删除图例 plt.gca().xaxis.set_major_locator(MaxNLocator(20)) plt.tight_layout() plt.savefig(output_path, dpi=150, bbox_inches='tight') plt.close() def plot_std_zscore_intervals(file_list, box_counts, intervals_std, intervals_zscore, output_path): """ 绘制标准差和Z-score最终稳定区间的二合一图 :param file_list: 文件名列表 :param box_counts: 原始预测框数量列表 :param intervals_std: 标准差方法的最终稳定区间 :param intervals_zscore: Z-score方法的最终稳定区间 :param output_path: 输出图片路径 """ plt.figure(figsize=(20, 10)) # 绘制整体趋势(原始数据) plt.plot(file_list, box_counts, 'b-', linewidth=1.5, label='预测框数量') # 计算全局最小值和最大值(用于颜色块填充) global_min = min(box_counts) - 0.5 global_max = max(box_counts) + 0.5 # 定义每种方法的颜色和标签 method_colors = { '标准差方法': ('green', '标准差稳定区间'), 'Z-score方法': ('purple', 'Z-score稳定区间') } # 绘制标准差方法的稳定区间 for i, (start, end) in enumerate(intervals_std): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['标准差方法'][0], alpha=0.3, zorder=0) # 添加区间标注 interval_counts = box_counts[start:end + 1] if interval_counts: avg_count = np.mean(interval_counts) std_dev = np.std(interval_counts) mid_idx = start + (end - start) // 2 if mid_idx < len(file_list): plt.annotate(f"区间{i + 1}: {start + 1}-{end + 1}\n均值: {avg_count:.1f}±{std_dev:.1f}", (file_list[mid_idx], avg_count), xytext=(0, 20), textcoords='offset points', ha='center', fontsize=10, bbox=dict(boxstyle="round,pad=0.3", fc="yellow", alpha=0.7), zorder=10) # 绘制Z-score方法的稳定区间 for i, (start, end) in enumerate(intervals_zscore): interval_files = file_list[start:end + 1] if not interval_files: continue plt.fill_between(interval_files, global_min, global_max, color=method_colors['Z-score方法'][0], alpha=0.3, zorder=0) # 添加区间标注 interval_counts = box_counts[start:end + 1] if interval_counts: avg_count = np.mean(interval_counts) std_dev = np.std(interval_counts) mid_idx = start + (end - start) // 2 if mid_idx < len(file_list): plt.annotate(f"区间{i + 1}: {start + 1}-{end + 1}\n均值: {avg_count:.1f}±{std_dev:.1f}", (file_list[mid_idx], avg_count), xytext=(0, -30), textcoords='offset points', ha='center', fontsize=10, bbox=dict(boxstyle="round,pad=0.3", fc="cyan", alpha=0.7), zorder=10) # 设置图表属性 plt.title('预测框数量变化趋势及稳定区间分析 - 标准差与Z-score方法合并', fontsize=18) plt.xlabel('图像文件名', fontsize=14) plt.ylabel('预测框数量', fontsize=14) plt.xticks(rotation=90, fontsize=7) plt.grid(True, linestyle='--', alpha=0.6) # 已删除图例 plt.gca().xaxis.set_major_locator(MaxNLocator(20)) plt.tight_layout() plt.savefig(output_path, dpi=150, bbox_inches='tight') plt.close() def save_interval_report(intervals, method_name, file_path, is_base=False, is_merged=False): """保存区间信息到文本文件""" interval_type = "基础区间" if is_base else "稳定区间" interval_type = "合并区间" if is_merged else interval_type with open(file_path, 'a') as f: f.write(f"\n{method_name} {interval_type}分析报告\n") f.write(f"{interval_type}数: {len(intervals)}\n") for i, (start, end) in enumerate(intervals): interval_counts = box_counts[start:end + 1] avg_count = np.mean(interval_counts) std_dev = np.std(interval_counts) cv = std_dev / avg_count if avg_count > 0 else 0 # 计算趋势斜率 x = np.arange(len(interval_counts)) slope, _, _, _, _ = linregress(x, interval_counts) f.write(f"\n区间 {i + 1}:\n") f.write(f" 起始文件索引: {start + 1} ({file_names[start]})\n") f.write(f" 结束文件索引: {end + 1} ({file_names[end]})\n") f.write(f" 文件数量: {end - start + 1}\n") f.write(f" 平均预测框数: {avg_count:.2f} ± {std_dev:.2f}\n") f.write(f" 变异系数: {cv:.4f}\n") f.write(f" 趋势斜率: {slope:.6f}\n") f.write(f" 最小值: {min(interval_counts)}, 最大值: {max(interval_counts)}\n") f.write("=" * 80 + "\n") def print_interval_info(intervals, method_name): """打印区间信息到控制台""" print(f"\n{method_name}发现 {len(intervals)} 个稳定区间:") for i, (start, end) in enumerate(intervals): interval_counts = box_counts[start:end + 1] avg_count = np.mean(interval_counts) std_dev = np.std(interval_counts) cv = std_dev / avg_count if avg_count > 0 else 0 # 计算趋势斜率 x = np.arange(len(interval_counts)) slope, _, _, _, _ = linregress(x, interval_counts) print(f"区间{i + 1}:") print(f" - 文件范围: {start + 1}-{end + 1} (共{end - start + 1}个文件)") print(f" - 平均框数: {avg_count:.2f} ± {std_dev:.2f}") print(f" - 变异系数: {cv:.4f}") print(f" - 趋势斜率: {slope:.6f}") print(f" - 最小值: {min(interval_counts)}, 最大值: {max(interval_counts)}") def merge_intervals(intervals, merge_gap=300, min_length=500): """合并重叠或接近的区间""" if not intervals: return [] # 按起始索引排序 intervals.sort(key=lambda x: x[0]) merged = [] current_start, current_end = intervals[0] for start, end in intervals[1:]: if start - current_end <= merge_gap: # 间隔小于合并阈值 current_end = max(current_end, end) # 扩展当前区间 else: merged.append((current_start, current_end)) current_start, current_end = start, end merged.append((current_start, current_end)) # 过滤短区间 final_merged = [ (start, end) for start, end in merged if (end - start + 1) >= min_length ] return final_merged # ====================== 主程序 ====================== if __name__ == "__main__": # 配置路径 label_dir = "E:/0718/0718-labels" # 替换为您的标签文件夹路径 output_dir = "E:/0718/0718-stable2" # 输出目录 os.makedirs(output_dir, exist_ok=True) # 获取文件列表并按自然顺序排序 file_list = [f for f in os.listdir(label_dir) if f.endswith(".txt")] file_list.sort(key=natural_sort_key) # 提取文件名(不含扩展名) file_names = [os.path.splitext(f)[0] for f in file_list] # 统计每个文件的预测框数量 box_counts = [] for file in file_list: file_path = os.path.join(label_dir, file) count = 0 with open(file_path, 'r') as f: for line in f: if line.strip(): # 非空行 count += 1 box_counts.append(count) # 计算整体统计数据 total_mean = np.mean(box_counts) total_std = np.std(box_counts) # 使用三种不同方法找出稳定区间 base_std, merged_std, intervals_std = find_stable_intervals( box_counts, method='std', min_window=500, max_window=2000, threshold=1.2, # 标准差阈值 merge_gap=0, min_length=0, return_base=True ) base_zscore, merged_zscore, intervals_zscore = find_stable_intervals( box_counts, method='zscore_avg', min_window=500, max_window=2000, threshold=0.75, merge_gap=0, min_length=0, return_base=True ) base_slope, merged_slope, intervals_slope = find_stable_intervals( box_counts, method='slope', min_window=500, max_window=2000, threshold=0.000025, # 趋势斜率阈值 merge_gap=0, min_length=0, return_base=True ) # ====================== 生成图表 ====================== # 生成三种方法的最终结果图片 output_std = os.path.join(output_dir, "box_count_stable_intervals_std.png") output_zscore = os.path.join(output_dir, "box_count_stable_intervals_zscore.png") output_slope = os.path.join(output_dir, "box_count_stable_intervals_slope.png") # 生成三种方法的基础区间图片(合并前) output_base_std = os.path.join(output_dir, "box_count_base_intervals_std.png") output_base_zscore = os.path.join(output_dir, "box_count_base_intervals_zscore.png") output_base_slope = os.path.join(output_dir, "box_count_base_intervals_slope.png") # 生成三种方法的合并区间图片(合并后但未过滤) output_merged_std = os.path.join(output_dir, "box_count_merged_intervals_std.png") output_merged_zscore = os.path.join(output_dir, "box_count_merged_intervals_zscore.png") output_merged_slope = os.path.join(output_dir, "box_count_merged_intervals_slope.png") # 生成合并图 output_combined = os.path.join(output_dir, "box_count_stable_intervals_combined.png") # 生成三合一基础区间图 output_combined_base = os.path.join(output_dir, "box_count_base_intervals_combined.png") # 生成标准差和Z-score基础稳定区间的二合一图 output_std_zscore_base = os.path.join(output_dir, "box_count_base_intervals_std_zscore.png") output_std_zscore = os.path.join(output_dir, "box_count_stable_intervals_std_zscore.png") # 绘制最终结果图表 plot_box_count_trend(file_names, box_counts, intervals_std, output_std, title_suffix="", method_name="标准差方法") plot_box_count_trend(file_names, box_counts, intervals_zscore, output_zscore, title_suffix="", method_name="Z-score方法") plot_box_count_trend(file_names, box_counts, intervals_slope, output_slope, title_suffix="", method_name="趋势斜率方法") # 绘制基础区间图(合并前) plot_box_count_trend(file_names, box_counts, base_std, output_base_std, title_suffix="", method_name="标准差方法", is_base=True) plot_box_count_trend(file_names, box_counts, base_zscore, output_base_zscore, title_suffix="", method_name="Z-score方法", is_base=True) plot_box_count_trend(file_names, box_counts, base_slope, output_base_slope, title_suffix="", method_name="趋势斜率方法", is_base=True) # 绘制合并区间图(合并后但未过滤) plot_box_count_trend(file_names, box_counts, merged_std, output_merged_std, title_suffix="", method_name="标准差方法") plot_box_count_trend(file_names, box_counts, merged_zscore, output_merged_zscore, title_suffix="", method_name="Z-score方法") plot_box_count_trend(file_names, box_counts, merged_slope, output_merged_slope, title_suffix="", method_name="趋势斜率方法") # 生成合并图 plot_combined_intervals(file_names, box_counts, intervals_std, intervals_zscore, intervals_slope, output_combined) # 生成三合一基础区间图 plot_combined_base_intervals(file_names, box_counts, base_std, base_zscore, base_slope, output_combined_base) # 生成标准差和Z-score基础稳定区间的二合一图 plot_std_zscore_base_intervals(file_names, box_counts, base_std, base_zscore, output_std_zscore_base) plot_std_zscore_intervals(file_names, box_counts, intervals_std, intervals_zscore, output_std_zscore) 去掉代码中合并相邻平稳段和过滤短时伪平稳段的部分
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值